Throw and catch Exception

image_pdfimage_print
   
 

using System;

class ExceptionThrower {
    static void MethodOne() {
        try {
            MethodTwo();
        } finally { }
    }

    static void MethodTwo() {
        throw new Exception("Exception Thrown in Method Two");
    }

    public static void Main(String[] args) {
        try {
            ExceptionThrower FooBar = new ExceptionThrower();
            MethodOne();
        } catch (Exception e) {
            Console.WriteLine(e.Message);
        } finally {
            // Cleanup code
        }
    }
}