[问题] SCJP 6题库126题:try-catch-finally

楼主: Su22 (装配匠)   2014-08-31 21:27:18
大家好
我想问这题
31. //some code here
32. try{
33. //some code here
34. }catch(Some Exception se) {
35. //some code here
36. }finally{
37. //some code here
38. }
Under which three circumstances will the code on line 37 be executed? (Choose
three.)
A. The instance gets garbage collected.
B. The code on line 33 throws an exception.
C. The code on line 35 throws an exception.
D. The code on line 31 throws an exception.
E. The code on line 33 executes successfully
答案BCE
B跟E没什么疑问

1.C在34行catch住exception并执行35行时若又发生错误
不会中断整个执行并将错误的exception先丢出吗?
2.选项A是干什么的?感觉跟这题没什么关系?
作者: kuangjc5566 (匡匡56)   2014-09-01 02:55:00
A选项来乱的。若35行throw exception,还是会执行 finally区块,然后更外层的try会尝试接这个exception。finally 区块除非遇到System.exit(),不然finally区块都会被执行。
楼主: Su22 (装配匠)   2014-09-01 23:34:00
感谢大大!

Links booklink

Contact Us: admin [ a t ] ucptt.com