"SCJP 1.6版考題 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. t...) |
(無差異)
|
於 2013年3月30日 (六) 03:46 的最新修訂
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)
| ||||||||||||||||||||