WinForm Exception Catching

Here’s a general way to catch most outside exceptions in your WinForm code.  Add this to your program wrapper:

Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

Of course, it is always better to handle specific cases with specific types of exceptions, but it is also nice to have a general handler for anything that escapes your exception handling.

This entry was posted in C#, WinForms. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>