/home/wpollock1/public_html/AJava/ExceptionDemo2.java
// This code shows what happens when a method calls another,
// which calls a third, which throws an exception. The middle
// method has a try-block, but it doesn't catch the type of
// exception thrown; it does have a finally clause however.
// Experiment with this code by changing the type of exception
// thrown, so it is caught by one of the handlers.
//
// Written 1/2014 by Wayne Pollock, Tampa Florida USA
public class ExceptionDemo2 {
public static void main ( String [] args ) {
try {
aMethod();
if (false) throw new java.io.IOException();
}
catch ( java.io.IOException any ) {
System.out.println( "In main exception handler" );
}
}
public static void aMethod () {
try {
bMethod();
}
catch ( ArithmeticException ae ) {
System.out.println( "In aMethod's exception handler" );
}
finally {
System.out.println( "In aMethod's finally clause" );
}
}
public static void bMethod () {
throw new ArrayIndexOutOfBoundsException("Oops!");
}
}