Typically, observable does not throw exceptions. Instead, by default,
Observable invokes its Observer`s onError() method, notifying the observer that
an unrecoverable error just occurred, and then quits without invoking any more
of its Observer`s methods.
The following error handling operators change the default behavior by resuming
or retrying the Observable sequence.
1)
2) Action on Error (doOnError)
3) Resume with Default Items
4) Resume with another sequence
5) Handle Exception Only
6) Resume on Error
With 'doOnError', we can invoke whatever action that is needed when there is
an error:
Observable
.error(UNKNOWN_ERROR)
.doOnError(throwable -> state.set(true))
.subscribe(testObserver);
In case of an exception being thrown while performing the action,
RxJava wraps the exception in a 'CompositeException':
Observable
.error(UNKNOWN_ERROR)
.doOnError(throwable -> {
throw new RuntimeException("unexcepted");
})
.subscribe(testObserver);