A custom exception with HelpLink and Source : Custom Exception : Language Basics C# Examples


C# Examples » Language Basics » Custom Exception »

 

A custom exception with HelpLink and Source









    
using  System;

public  class  CustomException  :  ApplicationException
{
    public  CustomException(string  Message)  :  base(Message)
    {
        this.HelpLink  =  "See  the  Readme.txt  file";
        this.Source  =  "My  Program";
    }
}

class  MainClass
{
    public  static  void  Main()
    {
        try
        {
            Console.WriteLine("Throwing  a  new  CustomException  object");
            throw  new  CustomException("My  CustomException  message");
        }
        catch  (CustomException  e)
        {
            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);
        }
    }
}
    
   
  
   



Output

Throwing a new CustomException object
HelpLink = See the Readme.txt file
Message = My CustomException message
Source = My Program
StackTrace =    at MainClass.Main()
TargetSite = Void Main()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Custom Exception