相关疑难解决方法(0)

try-finally和try-catch之间的区别

有什么区别

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子句访问异常?

java try-catch try-finally

82
推荐指数
4
解决办法
9万
查看次数

标签 统计

java ×1

try-catch ×1

try-finally ×1