August 2004
Intermediate to advanced
480 pages
9h 41m
English
The finally keyword is used after a try/catch block to indicate that the code inside the finally block should be executed whether the code inside the try block generates an exception or not. No matter what happens (unless someone pulls the plug on your box or externally kills your JVM process), the code in your finally block will run.
Do it like this:
try {
...
} catch (SomeEx se) {
...
} finally {
//put the code you want to run to matter what here.
}
Note that although the preceding code is how you will see it used 99% of the time, you can use the finally block without a catch block.
The finally statement is very useful, especially for doing complex operations involving files, a database, or a network connection, because there ...
Read now
Unlock full access