Catch statement without exception variable : Try Catch : Language Basics C# Examples


C# Examples » Language Basics » Try Catch »

 

Catch statement without exception variable









    
using  System;

class  MainClass
{
      static  void  Main()
      {
            int  x  =  10,  y  =  0;
            
            try  {  
            
                  x  =  x/y;  
            
            }catch  (System.IndexOutOfRangeException)  {  
            
                  Console.WriteLine("catch  clause");  
            
            }  finally  {  
            
                  Console.WriteLine("finally  clause");  
            
            }
      }
}
    
   
  
   



Output

Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero.
   at MainClass.Main()
finally clause


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Try Catch