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
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:
- Is it bad practice (and has anyone had problems when ignoring such exeptions).
- When
Connection.close()
does throw any exception. - 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