Is there a way to catch unhandled exceptions in the browser? #15634
Unanswered
koustubhmoharir
asked this question in
Q&A
Replies: 1 comment 1 reply
-
The best solution: handle errors in your code, never making unhandled exceptions part of the expected logic.
This one is pretty much how it always is. Any unhandled exception can lead to a broken state, and that's expected. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The approach recommended in the docs (try catch in Main) does not work for the browser, presumably because the event loop is separate from Main.
I found some PRs about an implementation of Dispatcher.UnhandledException that seem promising but it seems like they will offer only a partial solution. Is there some way to reliably catch any exception that occurs on the main thread for the purpose of logging? I don't want to attempt to recover from the exceptions, just log them.
Also, as of now, exceptions seem to just get logged to the browser console as warnings and then ignored, and Avalonia continues to run, possibly in a broken state.
In the absence of a solution, I am considering monkey patching console.warn and console.error in JavaScript as a last resort.
Beta Was this translation helpful? Give feedback.
All reactions