java IntelliJ IDEA:如何创建一个异常断点,该断点在所有异常 * 除外 * ClassNotFoundException 上停止?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6408596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ IDEA: How can I create an exception breakpoint that stops on all exceptions *except for* ClassNotFoundException?
提问by Dan Berindei
I'd like to run my test suite in the debugger and break on any unexpected exception, but the Java classloaders throw lots of ClassNotFoundExceptions during normal operation.
我想在调试器中运行我的测试套件并在任何意外异常时中断,但 Java 类加载器在正常操作期间抛出大量 ClassNotFoundExceptions。
So it would be nice if I could create an exception breakpoint that ignores ClassNotFoundExceptions and stops on everything else.
因此,如果我可以创建一个忽略 ClassNotFoundExceptions 并在其他所有事情上停止的异常断点,那就太好了。
回答by Jan
This answer is almost the same as that of Mindas, but the details were enough for me to ignore his suggestion the first time around, and bother the Intellij support guys/girls (thanks Serge and Eugene):
这个答案与 Mindas 的几乎相同,但细节足以让我第一次忽略他的建议,并打扰 Intellij 支持男孩/女孩(感谢 Serge 和 Eugene):
- Open the 'Breakpoints' window and go to the 'Exception Breakpoints' tab
- Highlight and activate the 'Any exception' breakpoint
Activate only the 'Condition' Condition and type in the following:
!(this instanceof java.lang.ClassNotFoundException)
- 打开“断点”窗口并转到“异常断点”选项卡
- 突出显示并激活“任何异常”断点
仅激活“条件”条件并输入以下内容:
!(this instanceof java.lang.ClassNotFoundException)
IDEA will remove 'java.lang' immediately (version 11.01), but it is required for this solution to work. If you don't use that, you will get a ClassNotFound popup box (irony oh irony).
IDEA 将立即删除“java.lang”(版本 11.01),但此解决方案需要它才能工作。如果你不使用它,你会得到一个 ClassNotFound 弹出框(讽刺哦讽刺)。
I did find out that a lot of 'standard' libraries throw exceptions in their normal flow of operations. When you successfully ignore the ClassNotFoundException's, you will find that others suddenly appear. Nothing is ever easy.
我确实发现很多“标准”库在它们的正常操作流程中抛出异常。当你成功忽略ClassNotFoundException的时候,你会发现其他的突然出现了。没有什么是容易的。
回答by adavea
For some reason I kept getting "failed to evaluate breakpoint expression" when I put the !ClassNotFoundException condition under the "any exception" breakpoint rules. I was able to work around it by creating a custom "any exception" breakpoint item though:
出于某种原因,当我将 !ClassNotFoundException 条件置于“任何异常”断点规则下时,我一直“无法评估断点表达式”。不过,我能够通过创建一个自定义的“任何异常”断点项来解决它:
- Open the breakpoints window from the debug view.
- Uncheck "Any Exception" so we will not be stopping at any exception using the default item.
- Click the + sign, click java exception breakpoints, check "Include Non-Project Classes", type "java.lang.Exception" in the box, select the result that shows up in the box.
Select the Exception item that is generated in the list (under "Any Exception"), and put
!(this instanceof java.lang.ClassNotFoundException)
in the condition box.
- 从调试视图打开断点窗口。
- 取消选中“任何异常”,这样我们就不会使用默认项在任何异常处停止。
- 点击+号,点击java异常断点,勾选“包含非项目类”,在框中输入“java.lang.Exception”,选择框中显示的结果。
选择列表中生成的异常项(在“Any Exception”下),然后放入
!(this instanceof java.lang.ClassNotFoundException)
在条件框中。
回答by mindas
- right click on the breakpoint, and click on
Properties
- go to
Conditions
pane - tick a checkbox at
Condition
- type
!(myException instanceof ClassNotFoundException)
- 右键单击断点,然后单击
Properties
- 转到
Conditions
窗格 - 勾选复选框
Condition
- 类型
!(myException instanceof ClassNotFoundException)