Reputation: 20707
We have a big application, and to ensure that our customers don't have the message "XXX has stopped working", we added some handler(in which we logs some errors and some other stuff).
It is working fine, we already solved a lot of issues like this(by analysis the logs after the exception arrived). But recently, someone managed to get the "XXX has stopped working" message anyway.
Currently we have the following implementation:
Application.ThreadException += HandleUnhandleException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += HandleUnhandleException;
Which is done at the very beginning of our application.
My question: Do you see any case where I can have an exception that display the mentionned popup("XXX has stopped working") without coming in this handler?
Upvotes: 2
Views: 227
Reputation: 10708
What do you mean by "the start of our application"?
I have found that on rare occaision, AppDomain
and Application
handlers can still fail even in the Main
function. One workaround is to put them in a static constructor of the same class as the entry point, as this preempts even Main
.
Some exceptions cannot be caught, such as the most obvious Stack Overflow, which will prevent catching and logging from happening. This can happen most often if your program enters an infinite recursive loop.
See the question on List of exceptions that CAN'T be caught in .NET as it may shed some more light on that.
Upvotes: 1