February 2020
Intermediate to advanced
412 pages
9h 36m
English
Similar to onErrorReturn() and onErrorReturnItem(), the onErrorResumeWith() operator (previously called onErrorResuumeNext() in RxJava 2.x) handles the exception too. 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 values in the event of an error:
import io.reactivex.rxjava3.core.Observable;public class Ch3_45 { public static void main(String[] args) { Observable.just(5, 2, 4, 0, 3) .map(i -> 10 / i) .onErrorResumeWith(Observable.just(-1).repeat(3)) .subscribe(i -> System.out.println("RECEIVED: " + i), e -> System.out.println( ...
Read now
Unlock full access