The Exception Hierarchy : Exception « Language Basics « C# / CSharp Tutorial






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);
        }
    }
}
DivideByZero System.DivideByZeroException: Attempted to divide by zero.
   at MainClass.Main()








1.17.Exception
1.17.1.The Exception Hierarchy
1.17.2.The System.Exception Class
1.17.3.A Closer Look at Exception
1.17.4.Using Exception members
1.17.5.Exception propagation with methods
1.17.6.An unhandled exception
1.17.7.Commonly Used Exceptions Defined Within the System Namespace
1.17.8.Handling a possible exception.