SCJP題庫第131題
Given:
11. static void test() throws Error{
12. if(true) throw new AssertionError();
13. System.out.print("test ");
14. }
15. public static void main(String[] args){
16. try{test();}
17. catch(Exception ex){System.out.print("exception ");}
18. System.out.print("end ");
19. }
What is the result?
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.
Ans: E
解說:
Test方法丟出一個AssertionError物件,但此錯誤物件型態不會被17行補捉到,因此main會丟出AssertionError(Throwable的子類別)而不正常結束
例外類別架構請參考講義258頁(SL-275)
Comments