Throw and catch Exception : throw : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » throw »

 

Throw and catch Exception








    
 

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
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» throw