public class NestedCatch { //----------------------------------------------------------------- // Deliberately access an array element that // is out of bounds to produce an exception. //----------------------------------------------------------------- public static void main (String[] args) { int[] a={1, 2, 3, 4, 5}; int numerator = 10; int denominator = 0; try { a[10] = 50; // this causes the exception try { System.out.println (numerator / denominator); } catch(ArithmeticException e) { System.out.println ("Caught an ArithmeticException."); System.out.println(e.getMessage()); } finally { System.out.println ("[INNER] This text will be printed."); } } catch(IndexOutOfBoundsException e) { System.out.println ("Caught an IndexOutOfBoundsException."); System.out.println(e.getMessage()); } finally { System.out.println ("[OUTER] This text will be printed."); } } }