我正在逐步通过这种结构编写一些代码:try { doSomething();} finally { doAnotherThing(); // more nested try statements down here} 某个地方正在触发异常,但我不知道它是否在doSomething()。因为doAnotherThing()无论是否触发了异常,代码都会转到,所以什么也没告诉我。触发异常时,某处是否有视觉指示?(IntelliJ 14.1.7)。
1 回答
![?](http://img1.sycdn.imooc.com/545845b40001de9902200220-100-100.jpg)
偶然的你
TA贡献1841条经验 获得超3个赞
在“运行”->“断点”菜单项下查看。您可以添加(使用“ +”按钮)“ Java异常断点”并指定要中断的异常类型。添加之后,您可以对try块中的另一个断点使用“禁用,直到命中选定的断点”,以将其限制为您关心的代码。“断点”窗口包含许多有用的控件,用于触发断点。
如果您需要知道是否引发了异常,则需要将其存储在代码中:
Throwable thrown = null;
try {
//Do very important work here
} catch (ImportantException e) {
thrown = e;
throw e;
} finally {
if (thrown != null) {
//We arrived in the finally block due to an exception
}
}
添加回答
举报
0/150
提交
取消