Use a custom Exception : Custom Exception : Language Basics C# Examples


C# Examples » Language Basics » Custom Exception »

 

Use a custom Exception









    
using  System;    
    
class  RangeArrayException  :  ApplicationException  {  
    public  RangeArrayException()  :  base()  {  }  
    public  RangeArrayException(string  str)  :  base(str)  {  }    
  
    public  override  string  ToString()  {  
        return  Message;  
    }  
}  
  
            
class  MainClass  {      
    public  static  void  Main()  {      
        try  {  
                  throw  new  RangeArrayException("Low  index  not  less  than  high.");    
        }  catch  (RangeArrayException  exc)  {  
              Console.WriteLine(exc);  
        }  
    }    
}
    
   
  
   



Output

Low index not less than high.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Custom Exception