ApplicationException is useless
Today is was skimming over MSDN when I was in the process of creating a custom exception to be used in our application. Normally, I stay clear of creating custom exceptions as I do not see a real need for using them in most cases and they just tend to deepen the exception hierarchy and not add too much value. But I felt that the situation I was trying to tackle did warrant a custom exception. So, I set about creating my own Exception class inheriting the ApplicationException class as suggested in the MSDN documentation. The MSDN says
ApplicationException is thrown by a user program, not by the common language runtime. If you are designing an application that needs to create its own exceptions, derive from the ApplicationException class. ApplicationException extends Exception, but does not add new functionality. This exception is provided as means to differentiate between exceptions defined by applications versus exceptions defined by the system.
Then I just so happened to stumble upon the “Community Content” for the ApplicationException class and was surprised to find information in there suggesting that inheriting from ApplicationException is useless. So, the “Community Content” does add value to MSDN… Anyway, I started digging around and found the following statement that concisely explains why inheriting from ApplicationException is useless.
JEFFREY RICHTER: System.ApplicationException is a class that should not be part of the .NET Framework. The original idea was that classes derived from SystemException would indicate exceptions thrown from the CLR (or system) itself, whereas non-CLR exceptions would be derived from ApplicationException. However, a lot of exception classes didn’t follow this pattern. For example, TargetInvocationException (which is thrown by the CLR) is derived from ApplicationException. So, the ApplicationException class lost all meaning. The reason to derive from this base class is to allow some code higher up the call stack to catch the base class. It was no longer possible to catch all application exceptions..
GOOD NEWS though… If you are currently using custom exceptions that inherit from ApplicationException then there is no need to go in and fix them. Inheriting from ApplicationException is not harmful just useless. That is what my dad used to say about me…