Reputation: 190897
Is there an elegant way to trap all unhandled exceptions in a Windows Form application? I would like to handle them and write them to a log file. I know ASP.NET has one. I'm using C#.
Upvotes: 0
Views: 200
Reputation: 101555
To trap uncaught exceptions on UI threads only, you can use Application.ThreadException
event.
To trap uncaught exceptions on all threads in the appdomain, use AppDomain.Current.UnhandledException
. The latter won't let you swallow the exception, however - you can log it in the handler, but once it returns, the exception will be handed over to Watson, which will display the usual Win32 crash dialog.
Upvotes: 1