add pendingException thing to track exceptions in finallys. Really tough to find problems if there is an error during an action but it then executes the @finally clause which causes an exception. First exception is LOST!
Donated by scott stanchfield:
No Format |
---|
Throwable pendingThrowable = null;
Connection connection = null;
try {
try {
connection = ... // open connection
// do database stuff
} catch(Throwable t) {
pendingThrowable = t;
}
} finally {
try {
if (connection != null) {
connection.close();
}
} catch(Throwable t) {
if (pendingThrowable != null) {
throw pendingThrowable;
}
throw t;
}
}
|