Chained Exceptions
November 24th, 2009.Filed under Programming.
Quick notes about chained exceptions, and exception handling in general. I’m going to run a simple client program which will throw exceptions forcing the chain to throw exceptions and these exceptions will be caught by the next callers catch block. Then I’m going to print out the exception stack trace to see the chain.

public class ExceptionClient {
public static void main(String[] args) {
try {
method1();
throw new Exception("Something is wrong");
} catch (Exception e) {
e.printStackTrace();
System.out.println("MAiN: " + e);
}
}// end Main()
public static void method1() throws Exception{
try {
method2();
} catch (Exception e) {
throw new Exception("Exception from method 2 " + e, e);
}
}
public static void method2() throws Exception{
try {
method3();
} catch (Exception e) {
throw new Exception("Exception from method 3 " + e, e);
}
}
public static void method3() throws Exception{
throw new Exception("Hello, World Problem !");
}
}
