<<< The catch Blocks | Index | Scanner input validation >>> |
The finally block executes
when the try block exits normally, or
when an exception occurs.
Therefore, the finally block always executes when the try block exits.
try { } catch (ExceptionType name) { } catch (ExceptionType name) { } finally { // always executes }
The finally block is a key tool for preventing resource leaks. Place the code in a finally block when closing a file or recovering other resources
<<< The catch Blocks | Index | Scanner input validation >>> |