Define exception variable in catch statement : Predefined Exception : Language Basics C# Examples


C# Examples » Language Basics » Predefined Exception »

 

Define exception variable in catch statement









    
using  System;

class  MainClass
{
      static  void  Main()
      {
            try
            {
                  int  y  =  0;
                  y  =  10/y;  
            }  catch  (DivideByZeroException  e)  {
                  Console.WriteLine("Message:  {0}",  e.Message);
                  Console.WriteLine("Source:  {0}",  e.Source);
                  Console.WriteLine("Stack:  {0}",  e.StackTrace);
            }
      }
}
    
   
  
   



Output

Message: Attempted to divide by zero.
Source: main
Stack:    at MainClass.Main()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Predefined Exception