Should I catch exceptions thrown when closing java.sql.Connection
- by jb
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?