Total .NET Analyzer Rule Documentation  

ExceptionBase Rule

Derive exceptions from System.ApplicationException or System.SystemException instead of from System.Exception.

Remarks

In general, you should avoid deriving user-defined exceptions from the Exception base class. Instead, you should derive custom exceptions from a derived class of System.Exception (usually System.ApplicationException or System.SystemException).

Both System.ApplicationException and System.SystemException extend System.Exception without adding new functionality. Use these base classes instead of System.Exception to differentiate between exceptions defined by applications and exceptions defined by the system.

Resolution

Most custom exceptions should not inherit from System.Exception; instead, they should be derived from System.ApplicationException (for application-specific exceptions) or System.SystemException (for system exceptions). For example, you would revise:

' VB
Public Class EmployeeNotFoundException
Inherits System.Exception
' Code here
End Class

// C#
public class EmployeeNotFoundException : ApplicationException
{
// Code here
}

To:

' VB
Public Class EmployeeNotFoundException
Inherits System.ApplicationException
' Code here
End Class

// C#
public class EmployeeNotFoundException : ApplicationException
{
// Code here
}

See Also

Best Practices for Handling Exceptions

Exception Hierarchy