-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Let exceptions crash the app #55
Comments
I guess it would be good (if you cant already) to register an optional exception handler and the default one would NOT catch and log the exception as it does currently. I find with a few libs i use when the exception is sucked up anywhere it can occasionally lead to wasted debugging time. |
+1 |
You can always catch the exception using the special exception event and re-throw it from a runnable posted to the main thread's Handler. |
thats useful to know - I would think it would make sense to have this as default behaviour for the sake of newcomers - I really dislike it when a lib sucks up exceptions by default from proir time spent debugging issues with other libs! |
@danielbenzvi Do I get this right, there's an event for exceptions within onEvent methods, I can register for this event like for any other event and then throw a RuntimeException myself? |
@asco33 correct. You can listen for the SubscriberExceptionEvent. You have access to the causing event, causing subscriber and the offending throwable. |
+1 Thanks for the work-around danielbenzvi! |
If EventBus will not handle exceptions in onEvent methods, they will be thrown in unpredictable and improper places. If subscriber is registered at the moment of posting event, exception will be thrown by post method (but it will be exception in subscriber!). Otherwise it will be thrown by registerSticky method, which is better but still unhandy. The way it works now is quite flexible, as you can handle exception exactly at the place it is thrown and do whatever you want, for example throwing runtime exception, as @danielbenzvi said above. One thing is that maybe @greenrobot should put detailed description for this into separate chapter in readme, as I suppose it can help many users. |
For anyone wondering what the code for that workaround would look like:
|
See #124 - Use builder.failFast(true) to enable. |
I cannot find the failFast method on the EventBus builder in version 2.4.0. Ist this implemented yet? If not, for what version is it planned? |
It got renamed to throwSubscriberException |
Hi, if I have an Exception that would normally crash the app within the onEvent callback method the app doesn't crash and the exception is logged by EventBus.
Is there a way to change that behaviour to the default one (exception -> crash) ?
The text was updated successfully, but these errors were encountered: