Skip to content

Exception bubbling in BlockingObservable #7267

Closed
@blacelle

Description

@blacelle

I consider RxJava 1.3.8 and its use by Azure Management Library. I consider a case of exception bubbling through their use of BlockingObservable. However, i'm not fully comfortable with BlockingObservable own exception handling.
Azure/azure-libraries-for-java#1397

Azure Management Library enables most of this API through Async and Sync operations. I focus here on the Sync API, which relies essentially over .toBlocking().single().body(). In such a case, if an exception occured in the flow of events (sorry for my poor choice of words, I'm not comfortable with Reactive programmation), I end in my own code with an exception produced by a different thread (in my case, a okhttp3 thread) : which is bad as I would expect an exception with a stack build on current thread, wrapping the exception from okhttp3 thread.

Some people state it is better to have less wrappers around an exception. (e.g. https://blog.danlew.net/2015/12/08/error-handling-in-rxjava/: I find it's easiest to deal with exceptions when they have the fewest wrappers around them. Exceptions.propagate() helps; it only wraps the exception if it's checked.)

I disagree with this statement. Indeed, exception wrapping is especially useful when one receive an exception generated from a different thread: wrapping the exception enables building a proper chain of stacks (from the calling thread+method to the failing thread+method).

I feel BlockingObservable fails to this as it relies on Exceptions.propagate which does not wrap RuntimeException, even through they would come from a different thread: as the API does not catch such a RuntimeException (which is OK in my perspective), it implies my own code receive directly the AzureLibrary exception (i.e. from OkHttp3 thread). Hence, if I myself leave the exception bubbling up without wrapping it, my final Exception Processor (e.g. Spring MVC @ControllerAdvice, or a generic UncaughtExceptionHandler) will process an exception from the OkHttp thread while it would much helpful to receive this exception wrapped in an exception attached to current thread.

Should Rxjava wrap exception while it is bubbling at least on any change of threads?
Should BlockingObservable force wrap the exception (instead of Exceptions.propagate wrapping all but RuntimeExceptions)?
Should Libraries and users of BlockingObservable catch for wrapping systematically to ensure propagating chained-exceptions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions