Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RXJava get object which caused exception in on error handler

Tags:

java

rx-java

is there any convenient way to get object which caused any exception in onError handler?

I want to do something like:

 observable.subscribe(
            unit -> {
               //something can throw ex here..
            },
            error->logger.error("error on {}", unit, error));
like image 421
hi_my_name_is Avatar asked Oct 20 '22 19:10

hi_my_name_is


1 Answers

Some errors will connect to a value, such as errors from map or filter. RxJava will call onError(rx.exceptions.OnErrorThrowable) for such errors. You can get the value from OnErrorThrowable.getValue.

However, some errors won't connect to a value. RxJava will just send the error directly to onError.

like image 116
zsxwing Avatar answered Nov 15 '22 05:11

zsxwing