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#.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To trap uncaught exceptions on UI threads only, you can use
Application.ThreadExceptionevent.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.