【系統公告】頁面上方功能列及下方資訊全面更換新版,舊用戶可再切回舊版。 前往查看

程式語言題庫

【非選題】
四、新的程式語言都會提供例外處理(exception handling)。請說明下列 Java 程式做例外
處理的可能流程。並且請說明 finally clause 的執行過程。(20 分)
public void writelist() throws ArrayIndexOutOfBoundsException {
PrintStream pStr = null;
try {
pStr = new PrintStream(
new BufferedOutputStream(
new FileOutputSteam("outfile")));
pStr.println("The 9th element is " +
victor.elementAt(9));
} catch (IOException e) {
System.err.println("i/o error");
} finally {
if (pStr != null) pStr.close();
}
}