Article Index

With apologies to A Few Good Men

“You want to catch the base exception?  You want to catch the base exception?  You can't handle the base exception!”  Ok, Jack never said that.  But he should have.

This is a very important point that hasn't hit home with a lot of co-workers.  I wonder if it stems from the VB habit of handling every error in a single On Error Goto statement (or worse, On Error Resume Next).  I'll admit, I didn't initially buy into it, until I had a good understanding of what it meant.  By catching the base exception, you are explicitly stating that you know how to handle the exception -- even though you don't know why it happened!  If you knew it could happen and how to handle it, you would catch that specific exception type. 

Granted, you need to be able to log the error, so you know that it happened.  That's where top-level “unhandled exception“ events come into play: AppDomain.UnhandledException, Application.ThreadException, and HttpApplication.Error.

For all the details go read Jason Clark's article in this month's MSDN Magazine.  He does a great job of explaining how to properly handle exceptions.  That's what inspired me to write this post.