有什么区别
try {
fooBar();
} finally {
barFoo();
}
Run Code Online (Sandbox Code Playgroud)
和
try {
fooBar();
} catch(Throwable throwable) {
barFoo(throwable); // Does something with throwable, logs it, or handles it.
}
Run Code Online (Sandbox Code Playgroud)
我更喜欢第二个版本,因为它让我可以访问Throwable.两种变体之间是否有任何逻辑差异或首选约定?
另外,有没有办法从finally子句访问异常?