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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access