Difference between try-finally and try-catch
- by Vijay Kotari
What's the difference between
try {
fooBar();
} finally {
barFoo();
}
and
try {
fooBar();
} catch(Throwable throwable) {
barFoo(throwable); // Does something with throwable, logs it, or handles it.
}
I like the second version better because it gives me access to the Throwable. Is there any logical difference or a preferred convention between the two variations?
Also, is there a way to access the exception from the finally clause?