public class MainClass {
public static void main(String[] args) {
int[] array = new int[]{1,0,2};
int index = 0;
try {
System.out.println("\nFirst try block in divide() entered");
array[index + 2] = array[index]/array[index + 1];
System.out.println("Code at end of first try block in divide()");
} catch(ArithmeticException e) {
System.err.println("Arithmetic exception caught in divide()\n" +
"\nMessage in exception object:\n\t" +
e.getMessage());
System.err.println("\nStack trace output:\n");
e.printStackTrace();
System.err.println("\nEnd of stack trace output\n");
} catch(ArrayIndexOutOfBoundsException e) {
System.err.println("Index-out-of-bounds exception caught in divide()\n" +
"\nMessage in exception object:\n\t" + e.getMessage());
System.err.println("\nStack trace output:\n");
e.printStackTrace();
System.out.println("\nEnd of stack trace output\n");
} finally {
System.err.println("finally clause in divide()");
}
System.out.println("Executing code after try block in divide()");
}
}
|