“尝试最终”和“尝试捕获”之间的区别
2022-08-31 10:11:13
两者之间有什么区别
try {
fooBar();
} finally {
barFoo();
}
和
try {
fooBar();
} catch(Throwable throwable) {
barFoo(throwable); // Does something with throwable, logs it, or handles it.
}
我更喜欢第二个版本,因为它让我可以访问Shrewable。这两种变体之间是否存在任何逻辑差异或首选约定?
另外,有没有办法从 finally 子句访问异常?