Custom Exceptions in C#

Dheeraj Kumar Gunti

Reading Time : ( words)

Custom Exceptions allows you to make more narrow, specific Exceptions with customized messages. Inherit the custom exception class with Application Exception. 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.


Things that to be taken care when designing custom exceptions,

  • Derive custom exceptions from System.Exception or other common base exception classes.
  • Custom Exceptions class need to Serializable, Exception need to be serialization so that it can be accessible across domains.