How to Design Exception Hierarchies

Krzysztof Cwalina, owner of the Framework Design Guidelines, has written a great post on designing exception hierarchies. He gives a great overview on the different categories of exceptions, which are placed under two main buckets he calls usage and system, and the right situations to throw them. This post also goes hand-in-hand with some of the…

0

FAQ: What exception should I throw instead of the reserved exceptions that DoNotRaiseReservedExceptionTypes warns against?

Throwing a general exception type such as System.Exception or System.SystemException in a library or Framework forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle (see FAQ: Why does FxCop warn against catch(Exception)? for reasons as to why this is bad). Instead, either throw a more derived type that already…

14

FAQ: Why does FxCop warn against catch(Exception)? – Part 3 [Nick Guerrera]

This is the third installment in a three-part series on why FxCop warns against catch(Exception):FAQ: Why does FxCop warn against catch(Exception)? – Part 1FAQ: Why does FxCop warn against catch(Exception)? – Part 2FAQ: Why does FxCop warn against catch(Exception)? – Part 3 I said from the beginning that this issue is controversial, and some of your feedback certainly confirms that….

22

FAQ: Why does FxCop warn against catch(Exception)? – Part 2 [Nick Guerrera]

This is the second installment in a three-part series on why FxCop warns against catch(Exception):FAQ: Why does FxCop warn against catch(Exception)? – Part 1FAQ: Why does FxCop warn against catch(Exception)? – Part 2FAQ: Why does FxCop warn against catch(Exception)? – Part 3 On Wednesday, I explained why catch (Exception) is a bad idea, and many of you replied with interesting…

28

FAQ: Why does FxCop warn against catch(Exception)? – Part 1 [Nick Guerrera]

This is the first installment in a three-part series on why FxCop warns against catch(Exception):FAQ: Why does FxCop warn against catch(Exception)? – Part 1FAQ: Why does FxCop warn against catch(Exception)? – Part 2FAQ: Why does FxCop warn against catch(Exception)? – Part 3 This question comes up a lot, and I think there’s a lot of confusion and controversy about the rule….

26

FAQ: Why do some sources recommend extending ApplicationException while FxCop does not? [Michael Fanning, David Kean]

TypesShouldNotExtendCertainBaseTypes fires on types that derive from ApplicationException and DoNotRaiseReservedExceptionTypes on members that throw ApplicationException. Why? There are several outdated documents floating around on the web (some orginally published by Microsoft) recommending that application developers extend ApplicationException. However, this guidance was revised several years ago for a couple of reasons: It deepens the class hierarchy and…

7