25.03.2013 Views

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Solutions to Chapter 14 | Java<br />

14 2 In Java, does <strong>the</strong> finally block gets executed if we insert a return statement inside <strong>the</strong><br />

try block of a try-catch-finally?<br />

SOLUTION<br />

Yes, it will get executed<br />

CareerCup com<br />

pg 78<br />

The finally block gets executed when <strong>the</strong> try block exists However, even when we attempt<br />

to exit within <strong>the</strong> try block (normal exit, return, continue, break or any exception), <strong>the</strong> finally<br />

block will still be executed<br />

Note: There are some cases in which <strong>the</strong> finally block will not get executed: if <strong>the</strong><br />

virtual machine exits in between try/catch block execution, or <strong>the</strong> thread which<br />

is executing try/catch block gets killed.<br />

2 2 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!