Which three are advantages of the Java exception mechanism?



A. Improves the program structure because the error handling code is separated from the normal program function
B. Provides a set of standard exceptions that covers all the possible errors
C. Improves the program structure because the programmer can choose where to handle exceptions
D. Improves the program structure because exceptions must be handled in the method in which they occurred
E. Allows the creation of new exceptions that are tailored to the particular program being created

題解

選項A,分割一般程式和例外處理程式,能讓程式的結構更淺顯易懂。

選項B,Java內建多種例外種類,只包含程式實作層面可能會發生的錯誤,並非全部的錯誤,如因硬體損壞而出現難以辨識的錯誤或是程式邏輯上的錯誤。

選項C,Java的程式設計師可以自行決定程式的哪些部份要進行例外處理。

選項D,例外不一定要在方法內進行處理,也可以將其丟出方法之外,交由執行緒來進行中斷。

選項E,可以針對特定程式建立新的例外。