io.reactivex.exceptions.UndeliverableException
io.reactivex.exceptions.UndeliverableException:java.net.UnknownHostException: Unable to resolve host “xx.xx.com”: No address associated with hostname
io.reactivex.plugins.RxJavaPlugins.void onError(java.lang.Throwable)(SourceFile:349)
在bugly中捕获到此问题,项目中用到的Rxjava操作符是Flowable一路追踪其subscribe方法发现了RxJavaPlugins.onError的身影:
@BackpressureSupport(BackpressureKind.SPECIAL)@SchedulerSupport(SchedulerSupport.NONE)@Overridepublic final void subscribe(Subscriber<? super T> s) {ObjectHelper.requireNonNull(s, "s is null");try {s = RxJavaPlugins.onSubscribe(this, s);ObjectHelper.requireNonNull(s, "Plugin returned null Subscriber");subscribeActual(s);} catch (NullPointerException e) { // NOPMDthrow e;} catch (Throwable e) {Exceptions.throwIfFatal(e);// can't call onError because no way to know if a Subscription has been set or not// can't call onSubscribe because the call might have set a Subscription already**RxJavaPlugins.onError(e);//这里调用了**NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");npe.initCause(e);throw npe;}}
错误信息中出现的这个onError语句,然后点击查看其实现方法
public static void onError(@NonNull Throwable error) {Consumer<? super Throwable> f = errorHandler;if (error == null) {error = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");} else {if (!isBug(error)) {error = new UndeliverableException(error);}}if (f != null) {//如果f不为null则就会调用f的accept方法try {f.accept(error);return;} catch (Throwable e) {// Exceptions.throwIfFatal(e); TODO decidee.printStackTrace(); // NOPMDuncaught(e);}}error.printStackTrace(); // NOPMDuncaught(error);}
–uncaught将UndeliverableException抛出?
如果f不为null则就会调用f的accept方法,f为errorHandler,然后就在RxJavaPlugins中搜索这个变量,发现其赋值方法:
/*** Sets the specific hook function.* @param handler the hook function to set, null allowed*/
public static void setErrorHandler(@Nullable Consumer<? super Throwable> handler) {if (lockdown) {throw new IllegalStateException("Plugins can't be changed anymore");}errorHandler = handler;
}
这样我们就可以通过设置errorHandler来捕获UndeliverableException异常。
private void setRxJavaErrorHandler() {
if(RxJavaPlugins.getErrorHandler()||RxJavaPlugins.lockdown) return;RxJavaPlugins.setErrorHandler(e -> {if (e instanceof UndeliverableException) {e = e.getCause();}if ((e instanceof IOException) || (e instanceof SocketException)) {// fine, irrelevant network problem or API that throws on cancellationreturn;}if (e instanceof InterruptedException) {// fine, some blocking code was interrupted by a dispose callreturn;}if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) {// that's likely a bug in the applicationThread.currentThread().getUncaughtExceptionHandler().handleException(Thread.currentThread(), e);return;}if (e instanceof IllegalStateException) {// that's a bug in RxJava or in a custom operatorThread.currentThread().getUncaughtExceptionHandler().handleException(Thread.currentThread(), e);return;}Log.warning("Undeliverable exception received, not sure what to do", e);
});
}
参考:
http://blog.csdn.net/sr_code_plus/article/details/77189478
https://github.com/ReactiveX/RxJava/wiki/What’s-different-in-2.0#error-handling
io.reactivex.exceptions.UndeliverableException相关推荐
- Rxjava源码分析之IO.Reactivex.CompositeDisposable
Rxjava 源码系列目录 Rxjava源码分析之IO.Reactivex.Observer Rxjava源码分析之IO.Reactivex.CompositeDisposable Rxjava源码分 ...
- Rxjava源码分析之IO.Reactivex.Observer
Android 中的观察者模式,Rxjava中有两个重要的类Observable和Observer,函数响应式编程具体表现为一个观察者(Observer)订阅一个可观察对象(Observable).通 ...
- Cannot resolve method ‘subscribe(anonymous io.reactivex.Observer<xxx>)‘的解决方案
在使用RxJava开发的时候有时会遇到类似Cannot resolve method 'subscribe(anonymous io.reactivex.Observer)'的错误提示. 咋一看sub ...
- rx.xxx 和 io.reactivex.xxx RxJava1 和 RxJava2 和 RxJava3
在使用RxJava想要创建一个Observable,导入包的时候发现 发现怎么这么多,我该选哪个? 上图 1位置的io.reactivex是代表了Rxjava2里面的Observable; 2 ...
- RxJava2出现:Unable to create call adapter for io.reactivex.Flowable
前面一直使用的是Rxjava 1.x 版本,最近 Rxjava 2.x 版本发布了,并且支持了背压,便换成了 Rxjava 2.x 版本.更换之后出现了下面的错误. Caused by: java.l ...
- Rxjava源码分析之IO.Reactivex.Observable
Rxjava 源码系列目录 Rxjava源码分析之IO.Reactivex.Observer Rxjava源码分析之IO.Reactivex.CompositeDisposable Rxjava源码分 ...
- RxAndroid io.reactivex.Scheduler无法转换为rx.Scheduler
io.reactivex.Scheduler无法转换为rx.Scheduler 这个是版本差异的问题 这个是报错的版本 //rxandroidimplementation 'io.reactivex. ...
- NoClassDefFoundError io.reactivex.Flowable
各路宝宝都看看这个异常: java.lang.NoClassDefFoundError: io.reactivex.Flowableat io.reactivex.Observable.bufferS ...
- Rx2.0后台开发分享
Rxjava2.x 微软的一个函数库,Rx是一个编程模型,模板是提供一致的编程接口,帮助开发者更方便的处理异步数据流,现在Rx已经支持几乎全部的流行编程语言.比较流行的有Rxjava,RxJs,Rx. ...
最新文章
- usaco Money system
- 在IDE中刷LeetCode,编码调试一体化,刷题效率直线up!
- java里面怎么添加表约束_mysql给表增加约束条件
- 厦门试点医疗大数据 产值有望达1200亿
- 面试必备:LinkedHashMap源码解析(JDK8)
- my02_Atlas mysql5.7安装配置
- Symfony2 生成应用包
- 职校计算机课堂评课标准,中职学校计算机专业课堂教学评价(共2323字).doc
- 搜索连接字符串存储过程【原创】
- rtt 打印 float
- MFC工作笔记0005---::在vc++中是什么意思
- retrofitWrap
- oracle怎么不让别的电脑连接,[转载]修改计算机名字导致oracle连接不上的解决方案...
- 使用python中正则表达式匹配linux ifconifg命令中的具体信息
- rman异机恢复数据库
- 这可能是最全的JAVA入门教程 ~
- n1盒子当无线打印服务器,n1下ubuntu安装cups配置airprint网络打印服务器
- 阿尔法营任务黑客机器人游戏答案
- 卡牌大师怎么玩_LOL高端局中的常客,卡牌大师上分攻略,最完美的节奏大师!...
- 阵列信号处理仿真二——波束方向图的绘制