Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I override the default uncaught exception dialog?

When an exception goes uncaught in a .NET app, the virtual machine displays an error message to the user. I'd like to be able to display my own error message, without having to put a catch block at the top level of my app (because that makes debugging uncaught exceptions more tedious).

Right now I display my own error dialog in an AppDomain.UnhandledException event listener, but the .NET-created dialog still shows up. I'd also like to avoid Environment.FailFast as that would bypass my finally blocks (to which I'm still somewhat attached).

like image 823
zneak Avatar asked Jul 04 '12 20:07

zneak


1 Answers

If this is WinForms, you have to handle AppDomain.UnhandledException and Application.ThreadException to catch them all. Some exceptions filter into one and others into the other.

There was a similar (but not exact duplicate) question here that should help: C# - WinForms - Exception Handling for Events

like image 146
David Avatar answered Sep 21 '22 16:09

David