#853 – An Exception Is an Instance of the System.Exception Class

When an exception is thrown, the method throwing the exception creates an instance of the System.Exception class and populates it with information about what went wrong.  This Exception object then travels up the call stack until a method that handles the exception is found.  This method “catches” the exception and can then query the Exception object to get information about the exception.

The exception must either be an instance of System.Exception or inherit (directly or indeirectly) from System.Exception.  A more specialized exception class is used when the method throwing the exception wants to include information in the exception object that is specific to the error that occurred.

For example, a method trying to read a file might throw a System.IO.FileNotFoundException.  This class inherits from System.IO.IOException, which inherits from System.SystemException, which in turn inherits from System.Exception.

For example:

853-001

Advertisements