rocky
rocky

Reputation: 5004

RXJava get object which caused exception in on error handler

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));

Upvotes: 5

Views: 628

Answers (1)

zsxwing
zsxwing

Reputation: 20826

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.

Upvotes: 3

Related Questions