如何判断在IntelliJ中进行调试时是否触发了Java异常?

我正在逐步通过这种结构编写一些代码:


try {

  doSomething();

} finally {

  doAnotherThing();

  // more nested try statements down here

某个地方正在触发异常,但我不知道它是否在doSomething()。因为doAnotherThing()无论是否触发了异常,代码都会转到,所以什么也没告诉我。


触发异常时,某处是否有视觉指示?(IntelliJ 14.1.7)。


茅侃侃
浏览 155回答 1
1回答

偶然的你

在“运行”->“断点”菜单项下查看。您可以添加(使用“ +”按钮)“ 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    }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java