illustrates a custom exception : Exception Class : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Exception Class »

 

illustrates a custom exception









    

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/
/*
  Example13_9.cs illustrates a custom exception
*/

using System;


// declare the CustomException class
class CustomException : ApplicationException
{

  public CustomException(string Message) : base(Message)
  {

    // set the HelpLink and Source properties
    this.HelpLink = "See the Readme.txt file";
    this.Source = "My Example13_9 Program";

  }

}


public class Example13_9
{

  public static void Main()
  {

    try
    {

      // throw a new CustomException object
      Console.WriteLine("Throwing a new CustomException object");
      throw new CustomException("My CustomException message");

    }
    catch (CustomException e)
    {

      // display the CustomException object's properties
      Console.WriteLine("HelpLink = " + e.HelpLink);
      Console.WriteLine("Message = " + e.Message);
      Console.WriteLine("Source = " + e.Source);
      Console.WriteLine("StackTrace = " + e.StackTrace);
      Console.WriteLine("TargetSite = " + e.TargetSite);

    }

  }

}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Class