[問題] SCJP 6題庫126題:try-catch-finally

看板java作者 (裝配匠)時間10年前 (2014/08/31 21:27), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
大家好 我想問這題 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是幹什麼的?感覺跟這題沒什麼關係? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.227.75.243 ※ 文章網址: http://www.ptt.cc/bbs/java/M.1409491641.A.187.html

09/01 02:55, , 1F
A選項來亂的。若35行throw exception,還是會執行 fin
09/01 02:55, 1F

09/01 02:55, , 2F
ally區塊,然後更外層的try會嘗試接這個exception。fi
09/01 02:55, 2F

09/01 02:55, , 3F
nally 區塊除非遇到System.exit(),不然finally區塊
09/01 02:55, 3F

09/01 02:55, , 4F
都會被執行。
09/01 02:55, 4F

09/01 23:34, , 5F
感謝大大!
09/01 23:34, 5F
文章代碼(AID): #1K0oAv67 (java)
文章代碼(AID): #1K0oAv67 (java)