java - 如何显示 catch 和 finally 的异常?
问题描述
让我们考虑以下代码:
try {
throw new Exception("from try")
} catch (Exception e) {
throw new Exception("from catch")
} finally {
throw new Exception("from finally")
}
它给:
Exception thrown
java.lang.Exception: from finally
<...>
所以看起来finally在catch之前执行并终止了执行流程。
如果想同时看到这两个例外,我该怎么办?
解决方案
所以看起来 finally 在 catch 之前执行并终止了执行流程。
这是不正确的。 finally
在对应的之后执行catch
,而不是之前。问题是您的catch
块执行,然后finally
保证块执行。
推荐阅读
- php - CakePHP4 Ajax:从控制器发送到视图
- latex - Doxygen:参数表的列宽问题
- compilation - 如何在 Tasmota 编译时设置规则
- sql - 使用 Union 和 string_split() 时子查询返回超过 1 个值
- google-api - Google Drive 使用导出 api 下载文件
- c# - 尝试更新 ViewModel 中的 Ui 属性时 DispatcherQueue null
- javafx - 从javafx中的窗格上的矩形溢出
- google-sheets - Google 表格中的 GA Beaccon 代码停止发送流量数据
- python - 我无法遍历我的列表,它只是说“列表索引必须是整数或切片,而不是 str”
- python - 需要帮助将自定义时隙分配给日期时间数据