Welcome to MSDN Blogs Sign in | Join | Help

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 presents additional complications for consumers writing exception handlers without providing additional value.
  • It prevents the reuse of existing exception classes defined in the Base Class Library (BCL).

The official Microsoft Design Guidelines, particularly the Catching and Throwing Standard Exception Types section, have only recently been revamped to include this new information. Both Krzysztof Cwalina and Brad Abrams, who own the Framework Design Guidelines at Microsoft, have both blogged on this issue (ApplicationException considered useless and Introducing the .NET Framework Standard Library Annotated Reference).

If you see any MSDN samples or articles that use ApplicationException (or violate any FxCop rule, for that matter), please file a bug on the Microsoft Connect.

Published Wednesday, April 05, 2006 8:21 PM by David M. Kean

Comments

Thursday, April 06, 2006 3:32 AM by Jared Parsons

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

Your link to "Catching and throwing Standard Exception Types" appears to be broken.
Thursday, April 06, 2006 9:13 AM by mcgurk

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

Rock on!  Where can I get aholt of the bass class library?  I've got some killer riffs I want to implement!
Thursday, April 06, 2006 9:51 AM by David M. Kean

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

Fixed and Fixed. ;)
Wednesday, April 12, 2006 1:53 PM by Peter

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

The Product Feedback link is broken (gives me a generic error with this URL: http://lab.msdn.microsoft.com/productfeedback/Error.aspx?errtype=http&errno=500) so I'll enter it here instead.

These new recommendations--"don't throw ApplicationException and don't derive from it"--coupled with the fact that ApplicationException is by definition not something the Framework will derive/throw, begs the question: What's the ApplicationException class to be used for now? And if the answer is "nothing," why isn't it marked as obsolete, since the recommendation in Brad's entry came out nearly 18 months ahead of .NET 2.0?

And when you say "several outdated documents floating around on the web," these include the official Microsoft .NET Framework documentation:

http://msdn2.microsoft.com/en-US/library/system.applicationexception(VS.80).aspx

I can certainly understand the reasons for reversing your advice regarding ApplicationException, I just wonder why the FxCop and a couple other blogs are the only ones that say so, and not more high-profile sources like the docs.
Wednesday, April 12, 2006 2:04 PM by David M. Kean

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

Peter,

The Microsoft Design Guidelines (as linked above) are the correct docs. I will file a bug internally regarding the ApplicationException docs.

Existing code both internally and externally derive from ApplicationException. As it is a breaking change to change the base of a class (especially an Exception), it can't be marked obsolete.
Wednesday, April 12, 2006 2:26 PM by David M. Kean

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

Saturday, June 10, 2006 2:00 AM by David M. Kean

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

The ApplicationException documentation has now been fixed: http://msdn2.microsoft.com/en-US/library/system.applicationexception(VS.80).aspx.
New Comments to this post are disabled
 
Page view tracker