2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by TheJohnSpecko
0

Create an exception class that derives from whatever general exception already in place. Define your custom exception's way to handle the exception you want. Implement it in your code the same way as the provided exception handling.

Pseudocode:

Class MyCustomException : System.Exception
{

     properties;
         
     if( condition == true )
         {
              //handle exception;
         }
     else if ( anotherCondition == true )
         {
              //handle exception in another way;
         }
     else
         {
              //handle exception another way;
         }
}

//implementation

try
{
      doSomething();
}
catch(MyCustomException ex)
{
      ex.Message();
}

Do not copy this code, it will not work. It is just to give you the general idea of how to go about creating and implementing custom exceptions.

Edited by TheJohnSpecko: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.