Given:

public class Test {

    static void dispResult(int[] num) {
        try {
            System.out.println(num[1] / (num[1] - num[2]));
        } catch (ArithmeticException e) {
            System.err.println("First exception");
        }
        System.out.println("Done");
    }

    public static void main(String[] args) {
        try {
            int[] arr = {100, 100};
            dispResult(arr);
        } catch (IllegalArgumentException e) {
            System.err.println("Second exception");
        } catch (Exception e) {
            System.err.println("Third exception");
        }
    }
}

What is the result?

A.

0
Done

B.

First Exception
Done

C.

Second Exception

D.

Done
Third Exception

E.

Third Exception

題解

程式第 5 行會因為 num 所參考到的陣列物件並沒有索引 2 這個位置,而拋出 ArrayIndexOutOfBoundsException。而這個 ArrayIndexOutOfBoundsException 並不是 ArithmeticException,所以不會被第 6 行的 catch 接到,而由「dispResult」方法繼續向外拋出,最終被第 18 行的 catch 接到,輸出「Third exception」。