问题的现象是Observer的onNext方法被调用后,它的onError方法也紧跟着被调用了……我的第一反应是RxJava的Bug?……
当然不是的……
@Override
public void onNext(T args) {
try {
if (!done) {
actual.onNext(args);
}
} catch (Throwable e) {
// we handle here instead of another method so we don't add stacks to the frame
// which can prevent it from being able to handle StackOverflow
Exceptions.throwIfFatal(e);
// handle errors if the onNext implementation fails, not just if the Observable fails
onError(e);
}
}
// handle errors if the onNext implementation fails, not just if the Observable fails
当onNext里我们的函数发生异常时,onError会被调用