Creating and throwing an exception object : Exception Throw : Language Basics C# Examples


C# Examples » Language Basics » Exception Throw »

 

Creating and throwing an exception object









    
using  System;

class  MainClass
{
    public  static  void  Main()
    {
        try
        {
            Exception  myException  =  new  Exception("myException");

            myException.HelpLink  =  "See  the  Readme.txt  file";
            myException.Source  =  "My  Program";
            throw  myException;
        }
        catch  (Exception  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

HelpLink = See the Readme.txt file
Message = myException
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
» Exception Throw