Should I catch exceptions thrown when closing java.sql.Connection

Posted by jb on Stack Overflow See other posts from Stack Overflow or by jb
Published on 2008-10-29T19:43:28Z Indexed on 2010/04/04 5:33 UTC
Read the original article Hit count: 260

Filed under:
|
|
|

Connection.close() may throw SqlException, but I have always assumed that it is safe to ignore any such exceptions (and I have never seen code that does not ignore them).

Normally I would write:

 try{
    connection.close();
 }catch(Exception e) {}

Or

 try{
    connection.close();
 }catch(Exception e) {
     logger.log(e.getMessage(), e); 
 }

The question is:

  1. Is it bad practice (and has anyone had problems when ignoring such exeptions).
  2. When Connection.close() does throw any exception.
  3. If it is bad how should I handle the exception.

Comment:

I know that discarding exceptions is evil, but I'm reffering only to exceptions thrown when closing a connection (and as I've seen this is fairly common in this case).

Does anyone know when Connection.close() may throw anything?

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc