Quiz 09-16: Exceptions and Interfaces¶
Exceptions and Interfaces Quiz
Quiz Figures
public class MultipleCatchExample {
public static void main(String[] args) {
try {
int a = 10, b = 0;
int[] array = {1, 2, 3};
int result = a / b; // Divides by zero
// Out of bounds array access on next line
System.out.println("Array element: " + array[5]);
} catch (ArithmeticException ae) {
System.out.println("Cannot divide by zero.");
} catch (ArrayIndexOutOfBoundsException aioobe) {
System.out.println("Invalid array index.");
} // try
System.out.println("Got to the end!");
} // main
} // MultipleCatchExample