@@ -117,6 +117,10 @@ public void onNext(T args) {
117
117
protected void _onError (Throwable e ) {
118
118
try {
119
119
RxJavaPlugins .getInstance ().getErrorHandler ().handleError (e );
120
+ } catch (Throwable pluginException ) {
121
+ handlePluginException (pluginException );
122
+ }
123
+ try {
120
124
actual .onError (e );
121
125
} catch (Throwable e2 ) {
122
126
if (e2 instanceof OnErrorNotImplementedException ) {
@@ -134,7 +138,11 @@ protected void _onError(Throwable e) {
134
138
try {
135
139
unsubscribe ();
136
140
} catch (Throwable unsubscribeException ) {
137
- RxJavaPlugins .getInstance ().getErrorHandler ().handleError (unsubscribeException );
141
+ try {
142
+ RxJavaPlugins .getInstance ().getErrorHandler ().handleError (unsubscribeException );
143
+ } catch (Throwable pluginException ) {
144
+ handlePluginException (pluginException );
145
+ }
138
146
throw new RuntimeException ("Observer.onError not implemented and error while unsubscribing." , new CompositeException (Arrays .asList (e , unsubscribeException )));
139
147
}
140
148
throw (OnErrorNotImplementedException ) e2 ;
@@ -144,11 +152,19 @@ protected void _onError(Throwable e) {
144
152
*
145
153
* https://github.com/Netflix/RxJava/issues/198
146
154
*/
147
- RxJavaPlugins .getInstance ().getErrorHandler ().handleError (e2 );
155
+ try {
156
+ RxJavaPlugins .getInstance ().getErrorHandler ().handleError (e2 );
157
+ } catch (Throwable pluginException ) {
158
+ handlePluginException (pluginException );
159
+ }
148
160
try {
149
161
unsubscribe ();
150
162
} catch (Throwable unsubscribeException ) {
151
- RxJavaPlugins .getInstance ().getErrorHandler ().handleError (unsubscribeException );
163
+ try {
164
+ RxJavaPlugins .getInstance ().getErrorHandler ().handleError (unsubscribeException );
165
+ } catch (Throwable pluginException ) {
166
+ handlePluginException (pluginException );
167
+ }
152
168
throw new RuntimeException ("Error occurred when trying to propagate error to Observer.onError and during unsubscription." , new CompositeException (Arrays .asList (e , e2 , unsubscribeException )));
153
169
}
154
170
@@ -159,11 +175,25 @@ protected void _onError(Throwable e) {
159
175
try {
160
176
unsubscribe ();
161
177
} catch (RuntimeException unsubscribeException ) {
162
- RxJavaPlugins .getInstance ().getErrorHandler ().handleError (unsubscribeException );
178
+ try {
179
+ RxJavaPlugins .getInstance ().getErrorHandler ().handleError (unsubscribeException );
180
+ } catch (Throwable pluginException ) {
181
+ handlePluginException (pluginException );
182
+ }
163
183
throw unsubscribeException ;
164
184
}
165
185
}
166
186
187
+ private void handlePluginException (Throwable pluginException ) {
188
+ /*
189
+ * We don't want errors from the plugin to affect normal flow.
190
+ * Since the plugin should never throw this is a safety net
191
+ * and will complain loudly to System.err so it gets fixed.
192
+ */
193
+ System .err .println ("RxJavaErrorHandler threw an Exception. It shouldn't. => " + pluginException .getMessage ());
194
+ pluginException .printStackTrace ();
195
+ }
196
+
167
197
public Subscriber <? super T > getActual () {
168
198
return actual ;
169
199
}
0 commit comments