4

I have a general error handling solution in my app which should be invoked whenever onError is called. Instead of implementing onError for every subscribe I have done this inside the Application class:

RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
    @Override
    public void handleError(final Throwable throwable) {
        new ErrorHandler().call(throwable);
    }
});

However I would like to have the ability to override this by implementing onError, and according to:

https://github.com/ReactiveX/RxJava/wiki/Plugins#rxjavaerrorhandler

This plugin allows you to register a function that will handle errors that are raised by RxJava but that cannot be handled by the ordinary RxJava onError notification process (for instance, if RxJava tries to propagate an error to a subscriber that has not implemented an onError handler).

This should have been the case where I have implemented onError. However when running the code handleError inside RxJavaErrorHandler still gets invoked first, even though I have implemented onError.

Update: According to zsxwing, the wiki has been updated with the correct description of RxJavaErrorHandler.

maclir
  • 3,218
  • 26
  • 39
  • 2
    I think this is an inaccuracy in the wiki... the `onError` handler is invoked wether or not there's an `onError` associated with the `Observer`, not only if there's none... if nobody confirms this on SO, you can try opening a discussion on RxJava's github issues – Simon Baslé Feb 20 '15 at 17:17
  • Is there any other way to accomplish what I want? – maclir Feb 22 '15 at 08:09
  • I think you use use `throwable instanceof OnErrorNotImplementedException` to check if missing an onError implementation. – zsxwing Feb 25 '15 at 08:00
  • 1
    I updated the wiki to fix the description of RxJavaErrorHandler – zsxwing Feb 27 '15 at 07:42

1 Answers1

0

What we did at work was make a subclass of observer that has a default implementation of onError that you can still override if need be. Seems to solve your use case.

FriendlyMikhail
  • 2,857
  • 23
  • 39