You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Juozas Baliuka <ba...@mail.lt> on 2003/11/02 21:12:24 UTC

[dbutils] Exception handling

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


Re: [dbutils] Exception handling

Posted by David Graham <gr...@yahoo.com>.
--- Juozas Baliuka <ba...@mail.lt> wrote:
> 
> 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
>         }
>     }

I agree that this isn't the best idea so I replaced calls to
closeQuietly() with DbUtils.close() in QueryRunner.

David

> 
> 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
> 


__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

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