1. 程式人生 > >處理 RxJava UndeliverableException異常

處理 RxJava UndeliverableException異常

出現異常:io.reactivex.exceptions.UndeliverableException
出現原因:呼叫了多次onError,正常來說,出現一次onError會走正常Observer處理,其他的會走Error handling ,可以通過以下捕捉多次的error:

RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
            @Override
            public void accept(Throwable e) {
                if (e instanceof
UndeliverableException) { e = e.getCause(); } if ((e instanceof IOException)) { // fine, irrelevant network problem or API that throws on cancellation return; } if (e instanceof
InterruptedException) { // fine, some blocking code was interrupted by a dispose call return; } if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) { // that's likely a bug in the application
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); return; } if (e instanceof IllegalStateException) { // that's a bug in RxJava or in a custom operator Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); return; } Logger.l("Undeliverable exception"); } });