commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juozas Baliuka" <bali...@mail.lt>
Subject [dbutils] Exception handling
Date Sun, 02 Nov 2003 20:12:24 GMT

Looks like it is not a very good practice:

 /**
     * Close a <code>Connection</code>, avoid closing if null and hide
     * any exceptions that occur.
     */
    public static void closeQuietly(Connection conn) {
        try {
            close(conn);
        } catch (SQLException sqle) {
            // quiet
        }
    }

Some "clever" Connection implememtation can throw meaningfull exceptions:

if(Thread.currentThread() != openThread ){
 throw new SQLException( Thread.currentThread() + " doe's not owns
connection" );
}

Logging is not the best practice to handle exeptions,
I think it is better to clear all resources in nested finally blocks and
delegate exeption handling for API user, or add new callback interface  with
method
"void handleThrowable(Throwable t)".

BTW "closeQuietly" hides SQLException only on "any exceptions that occur".


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message