Tuesday, October 14, 2008

Unhandled Exception

As I am working towards my master in information technology from Harvard university here in Cambridge, I attend a class currently taught by David Platt . The previous week assignment was about exceptions and I didn't know that there were two types of global exceptions that you can catch.

I used to know and use the event

Application.ThreadException +=
new System.Threading.ThreadExceptionEventHandler(
Application_ThreadException);

I just learned that this is not necessarily going to catch all unhandled exceptions, it will only catch all unhandled exception that occur in the UI thread.

If you really want to handle all unhandled exceptions then you need to broaden your scope and implement the domain unhandled exception event as follows.

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

I used to know about both events but didn't really know the difference until I learned about them from my TA (Kevin).

Go to this blog for more details


Have fun catching exceptions.

No comments: