Yes Yes. doOnError acts when the error passes through the stream at that particular point, so if the statement is before doOnError throw (s), your action will be called. However, if you put doOnError further, it may or may not be called, depending on which statements are in the chain.
Considering
Observer<Object> ignore = new Observer<Object>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(Object t) { } };
For example, the following code always raises doOnError:
Observable.<Object>error(new Exception()).doOnError(e -> log(e)).subscribe(ignore);
However, this code will not:
Observable.just(1).doOnError(e -> log(e)) .flatMap(v -> Observable.<Integer>error(new Exception())).subscribe(ignore);
Most statements will return exceptions that come from the downstream.
Adding multipe doOnError viable if you throw an exception through onErrorResumeNext or onExceptionResumeNext :
Observable.<Object>error(new RuntimeException()) .doOnError(e -> log(e)) .onErrorResumeNext(Observable.<Object>error(new IllegalStateException())) .doOnError(e -> log(e)).subscribe(ignore);
otherwise, you will register the same exception in several places in the chain.
source share