IntroductionSo you want to handle somehow all the unhandled exceptions in your application.
Usually you want to accomplish one of the following: Log the exception for later diagnostics
Present the user an unhandled exception UI, nicer than the defaultYou heard there’s an event you should register, or maybe you find one by mistake, but is it the correct one?Did you know there are four (!) different events for handling unhandled exceptions in the .NET framework? So what is the difference between them and when should we use each one?
This post will hopefully answer these questions.Note: this is NOT a replacement for try-catch blocks!
SummaryI’ll begin with the summary to avoid boring busy developers. In a typical WPF application you should use Application.Current.DispatcherUnhandledException for exceptions generated on the UI thread and AppDomain.CurrentDomain.UnhandledException for all the other exceptions. Now, for the details..
System.Windows.Forms.Application.ThreadExceptionThis event is used for catching unhandled exceptions only on UI threads created by WinForms. Other exceptions, generated on non-UI threads won’t arrive to this event. Use AppDomain.Current.UnhandledException to catch them.
Read more: Arik Poznanski's Blog
QR:
Usually you want to accomplish one of the following: Log the exception for later diagnostics
Present the user an unhandled exception UI, nicer than the defaultYou heard there’s an event you should register, or maybe you find one by mistake, but is it the correct one?Did you know there are four (!) different events for handling unhandled exceptions in the .NET framework? So what is the difference between them and when should we use each one?
This post will hopefully answer these questions.Note: this is NOT a replacement for try-catch blocks!
SummaryI’ll begin with the summary to avoid boring busy developers. In a typical WPF application you should use Application.Current.DispatcherUnhandledException for exceptions generated on the UI thread and AppDomain.CurrentDomain.UnhandledException for all the other exceptions. Now, for the details..
System.Windows.Forms.Application.ThreadExceptionThis event is used for catching unhandled exceptions only on UI threads created by WinForms. Other exceptions, generated on non-UI threads won’t arrive to this event. Use AppDomain.Current.UnhandledException to catch them.
Read more: Arik Poznanski's Blog
QR:
0 comments:
Post a Comment