Rxjava 报错io.reactivex.exceptions.UndeliverableException: java.lang.InterruptedException

在使用Rxjava进行线程调度时,模拟耗时操作,调用了Thread.sleep(10000);切到后台或者退出程序报这个错误,发现Thread没有try catch导致,不写编译时不报错,但是运行时报错或者添加如下代码解决问题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; } } });

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页