June 2018
Beginner
722 pages
18h 47m
English
A finally block can be added to a try block with or without a catch clause. The format looks like the following:
try { //code of the try block} catch (...){ //optional catch block code} finally { //code of the finally block}
If present, the code in the finally block is always executed just before the method is exited. Whether the code in the try block has thrown an exception, and whether this exception was processed in one of the catch blocks or if the code in the try block did not throw an exception, the finally block is still executed every time just before the method returns the control flow to the caller.
Originally, the finally block was used to close some resources used in the try block that needed to be closed. For example, ...
Read now
Unlock full access