} catch (SQLException exception) {
//If this is a connection from an external pool then closeStatement will close the connection.
//we must test the connection before that happens.
RuntimeException exceptionToThrow = null;
DatabaseException commException = processExceptionForCommError(session, exception, dbCall);
if (commException != null) throw commException;
try {// Ensure that the statement is closed, but still ensure that the real exception is thrown.
closeStatement(statement, session, dbCall);
} catch (SQLException closeException) {
}
if (exceptionToThrow == null){
throw DatabaseException.sqlException(exception, this, session, false);
}
throw exceptionToThrow;
} catch (RuntimeException exception) {
try {// Ensure that the statement is closed, but still ensure that the real exception is thrown.
closeStatement(statement, session, dbCall);
} catch (SQLException closeException) {
}
throw exception;
}
// This is in a separate try block to ensure that the real exception is not masked by the close exception.
try {
// if we are called from the ParameterizedBatchWritingMechanism then dbCall will not be null
//and we should try an release the statement
if (dbCall != null) {
releaseStatement(statement, dbCall.getSQLString(), dbCall, session);
} else {
closeStatement(statement, session, dbCall);
}
} catch (SQLException exception) {
DatabaseException commException = processExceptionForCommError(session, exception, dbCall);
if (commException != null) throw commException;
throw DatabaseException.sqlException(exception, this, session, false);
}
return returnValue;
}