RxJava Failable provides constructs for handling RxJava processing exceptions without interrupting continuous stream.
In order to start using Vert.x Failable add the following dependency to your Maven project:
<dependency>
<groupId>com.github.hekonsek</groupId>
<artifactId>rxjava-failable</artifactId>
<version>0.3</version>
</dependency>
The following example demonstrates how to create callback invoked whenever flat map block throws an exception:
import static com.github.hekonsek.rxjava.failable.FailableFlatMap.failableFlatMap;
...
Observable.just(0, 1, 2, 4).
compose(
failableFlatMap(i -> just(4/i), (cause, value) -> {
System.out.print("Error " + cause.getClass().getSimpleName());
System.out.println(" for value: " + value);
})
).subscribe(System.out::println);
The snippet above displays the following output:
Error ArithmeticException for value: 0
4
2
1
Please note that an invocation of a failure handles doesn't stop Observable
from processing. What is also important, the original value
processing of which caused the exception is sent to failure callback as well.
You can also use simplified syntax failable(...)
instead of failableFlatMap(...)
. For example:
observable.compose(failable(i -> i, (cause, value) -> {}));
This project is distributed under Apache 2.0 license.