【发布时间】:2011-02-20 17:54:09
【问题描述】:
有什么区别
try {
fooBar();
} finally {
barFoo();
}
和
try {
fooBar();
} catch(Throwable throwable) {
barFoo(throwable); // Does something with throwable, logs it, or handles it.
}
我更喜欢第二个版本,因为它让我可以访问 Throwable。这两种变体之间是否存在逻辑差异或首选约定?
另外,有没有办法从 finally 子句访问异常?
【问题讨论】:
标签: java try-catch try-finally