RxJava 将错误从 onError 传播到回调中的 parent
RxJava propogate error from onError to parent from callback
我正在尝试将错误从 onError
传播到来自 Observable
的 parent 调用者。
我总是得到 UndeliverableException
并且控制权没有回到我的 parent。如何控制 parent?
public class TestClass {
public void process() {
try {
test();
} catch (Exception ex) {
// Want control here if something goes wrong
}
}
private void test() {
// observable is defined before below call
observable.subscribeWith(new DisposableObserver<Demo>() {
@Override
public void onNext(Demo t) {
// Exception occured here
throw new CustomRunTimeException("Some Exception");
}
@Override
public void onError(Throwable e) {
// I receive CustomRunTimeException here
// how to propagate to caller?
}
@Override
public void onComplete() {
}
});
}
}
正如@akarnokd 所建议的,我在定义可观察对象时使用了阻塞订阅。现在,我可以在回调后收回控制权。
observable.blockingSubscribe();
我正在尝试将错误从 onError
传播到来自 Observable
的 parent 调用者。
我总是得到 UndeliverableException
并且控制权没有回到我的 parent。如何控制 parent?
public class TestClass {
public void process() {
try {
test();
} catch (Exception ex) {
// Want control here if something goes wrong
}
}
private void test() {
// observable is defined before below call
observable.subscribeWith(new DisposableObserver<Demo>() {
@Override
public void onNext(Demo t) {
// Exception occured here
throw new CustomRunTimeException("Some Exception");
}
@Override
public void onError(Throwable e) {
// I receive CustomRunTimeException here
// how to propagate to caller?
}
@Override
public void onComplete() {
}
});
}
}
正如@akarnokd 所建议的,我在定义可观察对象时使用了阻塞订阅。现在,我可以在回调后收回控制权。
observable.blockingSubscribe();