June 2017
Intermediate to advanced
400 pages
8h 44m
English
Similar to onErrorReturn() and onErrorReturnItem(), onErrorResumeNext() is very similar. The only difference is that it accepts another Observable as a parameter to emit potentially multiple values, not a single value, in the event of an exception.
This is somewhat contrived and likely has no business use case, but we can emit three -1 emissions in the event of an error:
import io.reactivex.Observable; public class Launcher { public static void main(String[] args) { Observable.just(5, 2, 4, 0, 3, 2, 8) .map(i -> 10 / i) .onErrorResumeNext(Observable.just(-1).repeat(3)) .subscribe(i -> System.out.println("RECEIVED: " + i), e -> System.out.println("RECEIVED ERROR: " + e) ); } }
The output of the preceding code snippet is ...
Read now
Unlock full access