Difference between try-finally and try-catch
Posted
by Vijay Kotari
on Stack Overflow
See other posts from Stack Overflow
or by Vijay Kotari
Published on 2010-05-18T06:15:14Z
Indexed on
2010/05/18
6:20 UTC
Read the original article
Hit count: 317
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?
© Stack Overflow or respective owner