Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onError not called for StackOverflowError? #6068

Closed
boris-petrov opened this issue Jul 3, 2018 · 4 comments
Closed

onError not called for StackOverflowError? #6068

boris-petrov opened this issue Jul 3, 2018 · 4 comments

Comments

@boris-petrov
Copy link

I'm not exactly sure on the semantics of onError (any of those - Single, Observable, etc) - it has a Throwable as an argument however I don't see it being called for StackOverflowError for example. Am I doing something wrong or is this by design? If this is by design, a few things:

  1. Why is this not written in the documentation?
  2. Why is onError passed a Throwable and not Exception?
  3. How do I actually catch ANY exception as I need to do some cleanup in all cases (unlock locks e.g.)?

Thanks!

@akarnokd
Copy link
Member

akarnokd commented Jul 3, 2018

StackOverflowError is considered fatal and is propagated via rethrows as you can't recover from it anyway.

https://github.com/ReactiveX/RxJava/blob/2.x/src/main/java/io/reactivex/exceptions/Exceptions.java#L50

#748

@boris-petrov
Copy link
Author

boris-petrov commented Jul 3, 2018

Thanks for the response. I've read some of the threads on the topic, it makes sense. Perhaps that should be documented somewhere though. And, still, I'm not sure how to handle my question number 3 - in "normal synchronous" Java I can do:

try {
    lockLocks();
} catch (Throwable t) {
    unlockLocks();
    throw t;
}

Which is "safe" in both senses - I unlock the locks and then I rethrow the lethal exception. How can I do the same in Rx?

P.S. Right now I do:

Action doFinally = () -> { unlockLocks() };
maybe.doOnDispose(doFinally).doOnEvent((_unused1, _unused2) -> doFinally.run())

But this doesn't work for StackOverflow...

@akarnokd
Copy link
Member

akarnokd commented Jul 3, 2018

Don't use locks and RxJava together.

@boris-petrov
Copy link
Author

boris-petrov commented Jul 3, 2018

Not exactly the answer I was looking for but thanks nevertheless! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants