在这个例子中,try块的第三个缺失可能性是什么?

时间:2016-01-28 03:29:24

标签: java try-catch function-try-block

public void writeList() {
    PrintWriter out = null;

    try {
        System.out.println("Entering" + " try statement");

        out = new PrintWriter(new FileWriter("OutFile.txt"));
        for (int i = 0; i < SIZE; i++) {
            out.println("Value at: " + i + " = " + list.get(i));
        }
    } catch (IndexOutOfBoundsException e) {
        System.err.println("Caught IndexOutOfBoundsException: "
                           +  e.getMessage());

    } catch (IOException e) {
        System.err.println("Caught IOException: " +  e.getMessage());

    } finally {
        if (out != null) {
            System.out.println("Closing PrintWriter");
            out.close();
        } 
        else {
            System.out.println("PrintWriter not open");
        }
    }
}

此方法的try块有三种不同的退出可能性;这是其中两个。

1)try语句中的代码失败并抛出异常。这可能是由新的FileWriter语句引起的IOException或由for循环中的错误索引值引起的IndexOutOfBoundsException。

2)一切都成功,try语句正常退出。

有人能告诉我,可能发生的第三种可能性是什么,但这里没有提到?

1 个答案:

答案 0 :(得分:0)

异常可以传播到堆栈中的下一个方法