Friday, December 26, 2014

Exception

Types of Exception

There are the following 2 types of exceptions:
  1. System Exception.
  2. Application Exception.
System Exception

An exception raised implicitly from some predefined condition is a “System Exception”. For example DivideByZeroException, FormatException, OverFlowException and NullReference Exception.

If you want to learn about system exceptions then read my article:

Finally Block

Application Exception

An exception that is raised explicitly by the programmer in the application on its own condition is an “Application Exception”.

It can also referred to as a “User Defined Exception”.

Now let's we learn how to develop our own User Defined Exception.

Use the following procedure to develop a User Defined Exception.

Step 1: Inherit a class from the Exception class.

For example : Exception

Step 2: Override the string message from the exception class.

For example:
Public override string Message
{
    get
   {
        Return “Display the error Message when Exception Occur”
   }
} 
Step 3: In the other class, if an exception occurs that throws an exception for the creation of an object of your own exception class then do something.

For example:

Throws new

No comments:

Followers

Link