February 2020
Intermediate to advanced
412 pages
9h 36m
English
This, too, is something you likely will use only with testing. It creates an Observable that immediately generates an onError event with the specified exception:
import io.reactivex.rxjava3.core.Observable;public class Ch2_22 { public static void main(String[] args) { Observable.error(new Exception("Crash and burn!")) .subscribe(i -> System.out.println("RECEIVED: " + i), e -> System.out.println("Error captured: " + e), () -> System.out.println("Done!")); }}
The second parameter of the subscribe(Consumer<String> onNext, Consumer<Throwable> onError) method prints the following line:
Error captured: java.lang.Exception: Crash and burn!
You can also provide the exception using a lambda expression so that it is created from ...
Read now
Unlock full access