Use a custom Exception : Custom Exception « Language Basics « C# / CSharp Tutorial






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); 
    } 
  }  
}
Low index not less than high.








1.24.Custom Exception
1.24.1.User-Defined Exception Classes
1.24.2.Use a custom Exception
1.24.3.Derived exceptions must appear before base class exceptions.
1.24.4.A custom exception with HelpLink and Source
1.24.5.Extends Exception
1.24.6.Create your own exception class based on Exception
1.24.7.CustomException is an application exception that supports remoting.