O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using doOnError()

.doOnError() is a bit of a different beast. It is used to intercept errors that haven't reached .subscribe() yet. You may wonder how this is possible; is because the flow can be intercepted and recovered from the exception. In such a case, the original exception will never reach the error handler if it is implemented in the .subscribe() section.

For example, we can build on a previous case with .onExceptionResumeNext():

Observable.<String>error(new RuntimeException("Crash!"))        .doOnError(e -> log("doOnNext", e))        .onExceptionResumeNext(Observable.just("Second"))        .subscribe(item -> {            log("subscribe", item);        }, e -> log("subscribe", e));

Here, we've added a line:

        .doOnError(e -> log("doOnNext", e))

It will intercept the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required