Thursday, June 15, 2006

Visual Studio Managed Code Analysis (FxCop) : FAQ: Why does FxCop warn against catch(Exception)? [Nick Guerrera]

In his recent posting titled "FAQ: Why does FxCop warn against catch(Exception)?":, Nick Guerrera does a great job of explaining best practice in exception handling.

I’ve heard a lot of arguments against DoNotCatchGeneralExceptionTypes, but they generally boil down to one or both of the following:
  • “If I call an API which doesn’t document which exceptions it can throw, then I have no choice but to catch all possible exceptions!”

  • “My application needs to be robust; it can’t crash just because of an exception that I forgot to handle!”
Well worth reading and thinking about how you code your exception handling routines - I know for one I use catch (Exception e) w-a-y too much!

No comments: