The Exception Hierarchy : Exception : Language Basics C# Examples


C# Examples » Language Basics » Exception »

 

The Exception Hierarchy





An exception is an error that occurs at runtime.




    
using  System;

class  MainClass{
        
        public  static  void  Main(){
                int  Zero  =  0;
                try  {
                        int  j  =  22  /  Zero;
                }  catch  (DivideByZeroException  e)  //  catch  a  specific  exception
                {
                        Console.WriteLine("DivideByZero  {0}",  e);
                }  catch  (Exception  e)//  catch  any  remaining  exceptions
                {
                        Console.WriteLine("Exception  {0}",  e);
                }
        }
}
    
   
  
   



Output

DivideByZero System.DivideByZeroException: Attempted to divide by zero.
   at MainClass.Main()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Exception