Section 11.6 finally Block
• Programs that obtain certain types of resources must return them to the system to avoid so-called resource leaks (p. 454). Resource-release code typically is placed in a finally
block (p. 454).
• The finally
block is optional. If it’s present, it’s placed after the last catch
block.
• The finally
block will execute whether or not an exception is thrown in the corresponding try
block or any of its corresponding catch
blocks.
• If an exception cannot be caught by one of that try
block’s associated catch
handlers, control proceeds to the finally
block. Then the exception is passed to the next outer try
block.
• If a catch
block throws an exception, the finally
block still executes. Then the exception is passed to the ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.