IntelliJ中是否有“Breaking on Exception”?

本文翻译自:Is there “Break on Exception” in IntelliJ?

Is there feature that will automatically break debugging on first exception occurrence? 是否有功能会在第一次发生异常时自动中断调试?

So we 所以我们

  1. start application 开始申请
  2. do something that throw exception 做一些抛出异常的事情
  3. 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. 如果需要,可以通过条件或类过滤异常,或者您是否对捕获或未捕获的异常感兴趣。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IntelliJ IDEA 支持实时代码分析,这种特性被称为 “Inspections”。实时代码分析允许IDE在您编写代码的同时检查潜在的错误和不合规的代码片段,以便即时反馈和改进编码习惯。以下是关于实时代码分析的一些关键特点: 1. **代码检查(Inspections)**:在您输入代码时,IntelliJ IDEA 会自动执行一系列预设的检查,识别出常见的编程错误、最佳实践缺失、不安全的操作等问题,并给出相应的提示和修复建议。 2. **动态反馈**:当您敲击键盘并在编辑器移动光标时,IDE 可能会立即弹出警告、错误消息或推荐的修改,无需等待保存或刷新代码。 3. **可定制的检查**:用户可以根据需要调整检查设置,选择启用或禁用特定的检查项,甚至创建自定义的检查规则,以适应个人或团队的编码风格和规范。 4. **即时更新**:一旦完成检查,无论是在单个文件还是整个项目范围内,所作的更改都会立即反映在代码上,使得调试过程更为高效。 5. **增强的学习体验**:通过持续不断的实时代码分析,开发人员可以在实践学习正确的编程习惯,减少因粗心导致的错误,并提升整体代码质量和开发效率。 为了充分利用实时代码分析功能,开发者应该定期接受相关培训,理解IDE提供的各种检查项及其含义,并根据项目的实际需求调整检查设置。这对于培养良好的编码习惯和提高软件开发的质量至关重要。 --- 相关问题: 1. IntelliJ IDEA 如何管理代码检查规则? 2. 实时代码分析在大型项目的作用是什么? 3. 怎样在IntelliJ IDEA自定义代码检查功能?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值