Thursday, September 11, 2008

Taxonomy of Exceptions

Eric Lippert offers an interesting taxonomy of exceptions:

Fatal exceptions are not your fault, you cannot prevent them, and you cannot sensibly clean up from them.  [...]

Boneheaded exceptions are your own darn fault, you could have prevented them and therefore they are bugs in your code. [...]

Vexing exceptions are the result of unfortunate design decisions.  [...]

And finally, exogenous exceptions [...] are the result of untidy external realities impinging upon your beautiful, crisp program logic.

When I worked on DevPartner Fault Simulator (now unfortunately discontinued) we dealt with understanding these kinds of exceptions both in code Fault Simulator analyzed and in our own code.

As Eric points out,  writing good error handling code is hard in any language, whether you have exception handling or not.  I see far to much code that either simply ignores return values or overly aggressively catches exceptions.  Eric's taxonomy is a useful way to think about how your code should handle (or not) error conditions.

No comments: