在此示例中,try 块的第三个缺失可能性是什么?
in this example, what is the third missing possibility for the 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语句正常退出。
谁能告诉我,这里没有提到的第三种可能发生的可能性是什么?
异常可以传播到堆栈中的下一个方法
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语句正常退出。
谁能告诉我,这里没有提到的第三种可能发生的可能性是什么?
异常可以传播到堆栈中的下一个方法