public class OutOfBounds_Caught { //----------------------------------------------------------------- // 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}; try { a[10] = 50; // this causes the exception } catch(IndexOutOfBoundsException e) { System.out.println ("Caught an IndexOutOfBoundsException."); System.out.println(e.getMessage()); } finally { System.out.println ("This text will be printed."); } } }