天天看點

[CareerCup] 14.2 Try-catch-finally Java中的異常處理

14.2 In Java, does the finally block get executed if we insert a return statement inside the try block of a try-catch-finally?

這道題問我們Java中的finally塊是否會被執行,當我們在try中加入了傳回return。

答案是即便try中加入了return或者continue或者break等指令,finally塊仍然會被執行。但是下列兩種情況下finally裡的内容不會被執行:

1. 當虛拟機Virtual Machine在try/catch子產品中就退出了的時候

2. 當線程在處理try/catch子產品就結束了的時候