/** * Poor (not) handling an exception. In this case the attempt is to just * keep throwing the exception until you are outside teh program Doing so does * not work ... AND even if it did it would be bad. * * @author gtowell Created Feb 11, 2020 */ public class CatchErr1 { /** * A bad function for printing an array. It always just prints 10 items * * @param data the array to be printed. * @throws ArrayIndexOutOfBoundsException */ private void printArray(int[] data) throws ArrayIndexOutOfBoundsException { for (int i = 0; i <= 10; i++) { System.out.println(data[i]); } } /** * Main to trigger problem with printArray. An attempt is made to handle the * problem by throwing it along. This does not work! * * @param args unused * @throws ArrayIndexOutOfBoundsException */ public static void main(String[] args) throws ArrayIndexOutOfBoundsException { new CatchErr1().printArray(new int[5]); System.out.println("Done printing the array!"); } }