public class ExceptionTest1 {
  public static void main(String[] args) {
    
    int[] a = {5, 1, 0};
    int b = 0;
    for(int i =0; i <= 3; i++) 
      try {
        b = middleMethod(a,i);
      } catch(ArithmeticException e) {
        System.out.println("Attempted zero divide.");
      } catch(ArrayIndexOutOfBoundsException e) {
        System.out.println("Array index out of bounds.");
      } finally {
        System.out.println("Value of i is " + i);
      }
  }

  public static int middleMethod(int[] a, int i) {
    return lowMethod(a, i);
  }

  public static int lowMethod(int[] a, int i) {
    return 15/a[i];
  }

}
