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
}
}
}
Related examples in the same category