Exception handling with trying and catching : Try Catch : Language Basics C# Examples


C# Examples » Language Basics » Try Catch »

 

Exception handling with trying and catching









    
using  System;

class  MainClass{
        
        
        public  static  void  Main(){
                Console.WriteLine("Before  catch");
                int  Zero  =  0;
                try  {
                        int  j  =  22  /  Zero;
                }  catch  (Exception  e)  {
                        Console.WriteLine("Exception  "  +  e.Message);
                }
                
                Console.WriteLine("After  catch");
        }
}
    
   
  
   



Output

Before catch
Exception Attempted to divide by zero.
After catch


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Try Catch