You can also called that create user defined exception class in asp.net.
There is a situations where you need to create and handle a custom exception for handling runtime’s exception for application-specific exceptions.
In this example we provide both C#.Net Example and VB.Net Example.
Let's look how this mechanism works.
For that we need to create a serializable class that extends the System.Exception class, and ass some constructors and properties to manipulate the data members.
You can throw custom exception class object exception in Try block and it will handle in catch block. Mark your custom exception class as sealed if you do not wish other exception classes to extend it. You need to Implement three public constructors with specific signature and they call base class constructor.
You also need to make custom exception class serializable so that the runtime can marshal instances of your exception. If your exception class declares custom data members, so you must override the ISerializable. GetObjectData method of the Exception class as well as implement a deserialization constructor with appropriate signature. If your exception class is sealed then mark the deserialization constructor as private, otherwise, mark it as protected. The GetObjectData method and deserialization constructor must call the equivalent base class method to allow the base class to serialize and deserialize its data correctly.
Here is example for this.