Hi,
I am working with a piece of code that looks like this:
Code:
public void foo() throws FooException {
try {
try {
openDBConnection();
doSomething();
closeDBConnection();
} catch (Exception e) {
logError(e);
throw new FooException(e);
}
} catch (Exception e) {
throw new FooException(e);
} finally {
closeDBConnection();
}
}
The code is suspected to cause DB connection leaks.
Question: suppose doSomething() fails and throws an exception. It should be caught by the first catch block, then it gets re-thrown inside FooException and then it's caught in the second catch block and re-thrown up the stack. The finally block should always execute. Is that correct? Or is there a scenario where the finally block would be skipped?
Thanks