Share via


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.

Comments

  • Anonymous
    April 05, 2006
    Your link to "Catching and throwing Standard Exception Types" appears to be broken.
  • Anonymous
    April 06, 2006
    Rock on!  Where can I get aholt of the bass class library?  I've got some killer riffs I want to implement!
  • Anonymous
    April 06, 2006
    Fixed and Fixed. ;)
  • Anonymous
    April 12, 2006
    The comment has been removed
  • Anonymous
    April 12, 2006
    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.
  • Anonymous
    April 12, 2006
    Just had a look, and a customer has already filed it:

    http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=ffeda598-cf85-4076-8683-1d6b6607d5c3
  • Anonymous
    June 09, 2006
    The ApplicationException documentation has now been fixed: http://msdn2.microsoft.com/en-US/library/system.applicationexception(VS.80).aspx.