Handle error gracefully and continue. : Try Catch : Language Basics C# Examples


C# Examples » Language Basics » Try Catch »

 

Handle error gracefully and continue.









    
using  System;  
  
class  MainClass  {  
    public  static  void  Main()  {  

            try  {  
                int  j=  0;
                int  i  =  5/j;
            }  
            catch  (DivideByZeroException)  {  
                //  catch  the  exception  
                Console.WriteLine("Can't  divide  by  Zero!");  
            }  

    }  
}
    
   
  
   



Output

Can't divide by Zero!


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Try Catch