本文翻译自:Is there “Break on Exception” in IntelliJ?
Is there feature that will automatically break debugging on first exception occurrence? 是否有功能会在第一次发生异常时自动中断调试?
So we 所以我们
- start application 开始申请
- do something that throw exception 做一些抛出异常的事情
- got IntelliJ popped up highlighted line where exception occurred. IntelliJ弹出突出显示异常发生的行。
#1楼
参考:https://stackoom.com/question/3vBK/IntelliJ中是否有-Breaking-on-Exception
#2楼
If you click on the little "+" sign in the upper left corner, you can add a new breakpoint. 如果单击左上角的小“+”符号,则可以添加新断点。 If you select Exception Breakpoint, you get a little dialog where you can enter the exception class to break on (in case you don't want to break on all exceptions). 如果选择Exception Breakpoint,则会得到一个小对话框,您可以在其中输入要断开的异常类(如果您不想中断所有异常)。
#3楼
In IntelliJ IDEA 14 go to: 在IntelliJ IDEA 14中,请访问:
Run -> View Breakpoints -> Check "Java Exceptions Breakpoints" -> Uncheck "Caught Exceptions"
If you do not uncheck Caught Exceptions
the execution will be stopped every time the Java Framework
throws an internal exception. 如果不取消选中Caught Exceptions
,则每次Java Framework
抛出内部异常时都会停止执行。
#4楼
A fast way to pop up the dialog is to press Ctrl + SHIFT + F8 (On Mac: Cmd + SHIFT + F8 ), then click over to the exception breakpoints tab. 弹出对话框的一种快速方法是按Ctrl + SHIFT + F8 (在Mac上: Cmd + SHIFT + F8 ),然后单击转到异常断点选项卡。 If that was the last tab you were viewing, it'll still be selected, making it easy to flick breaking on exceptions on and off. 如果这是您正在查看的最后一个标签,它仍然会被选中,这样就可以轻松地打开和关闭异常。
This will cause IntelliJ to break at the point in the code (or library code) where the exception was raised. 这将导致IntelliJ在引发异常的代码(或库代码)中断点。 Specifically, you get a 'first chance' at exception handling, before the stack is walked looking for catch/finally blocks to execute. 具体来说,在执行堆栈查找catch / finally块之前,您将获得异常处理的“第一次机会”。
TIP: Java tends to throw a lot of exceptions internally when loading classes, so this breaking on all exceptions can become quite tedious. 提示:Java在加载类时往往会在内部抛出大量异常,因此打破所有异常会变得相当繁琐。 The good news is that you can exclude certain types of exception using the condition field. 好消息是您可以使用条件字段排除某些类型的异常。
For example: 例如:
!(this instanceof java.lang.ClassNotFoundException)
You can chain multiple such conditions together with &&
. 您可以将多个此类条件与&&
链接在一起。
#5楼
Run | 运行| View Breakpoints | 查看断点| Exception Breakpoints 异常断点
#6楼
Yes, there is. 就在这里。 You need to define an exception breakpoint (it can be "Any exception") in the breakpoints dialog in IntelliJ IDEA. 您需要在IntelliJ IDEA的断点对话框中定义异常断点(可以是“任何异常”)。
The exceptions can be filtered by condition or class if desired, or by whether you are interested in caught or uncaught exceptions. 如果需要,可以通过条件或类过滤异常,或者您是否对捕获或未捕获的异常感兴趣。