Java Reference
In-Depth Information
getTranslate (String message) {
try {
// Get a database connection from the connectionManager pool.
dbConnection = connectionManager.getConnection();
...
// use dbConnection to read the database.
// This can cause an Exception to be thrown
messageFound = dbConnection.read();
...
}
catch (IOException e){
// Build a NoDatabaseAvailableException.
// Add some context information, such as the message
// you are trying to translate, the language code
// and the text from the current exception.
NoDatabaseAvailableException noDB = new
NoDatabaseAvailableException
(message + languageCode + e.toString());
throw .noDB;
}
finally {
// This statement will always be executed.
// Make sure the dbConnection is returned to the
// connectionManager pool.
connectionManager.releaseConnection(dbConnection);
}
}
This
finally
code block will always be performed. It holds for the following
conditions:
The
try
block completes normally.
The
try
block explicitly throws an exception that is caught in a related
catch
block.
The
try
block explicitly throws an exception that is not caught in a related
catch
block.
The
try
block executes a return statement.
The
try
block causes an exception to be thrown in some other class, which is
caught in a related
catch
block.
The
try
block causes an exception to be thrown in some other class, which is
not caught in a related
catch
block.