在Eclipse IDE中调试Java时将异常作为表达式捕获 [英] Catching exceptions as an expression while debugging Java in Eclipse IDE

查看:334
本文介绍了在Eclipse IDE中调试Java时将异常作为表达式捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java开发人员的日常调试情况是抛出异常,然后您需要挖掘调试器以了解其中的内容。通常,您将尝试在引发异常之前设置一些断点,并希望您能够确定导致该异常的情况。



在Eclipse中,断点可能有一个表达式定义在哪里,只有当例如变量x等于y时触发。我的问题是,是否可以定义某种全局表达式,一旦抛出异常,它被调试器捕获,允许程序员立即检查所有变量?理想情况下,你不会碰到catch块,Eclipse会捕获引发的异常,并且不改变堆栈内容就停止执行。



这是可能的还是受到JVM?

解决方案

另一个例子: )。





官方帮助主题 添加Java异常断点 有更多的这个。




  • 未捕获的异常选项是当异常类型与断点被抛出未被捕获的位置。

  • 捕获异常选项是在被捕获的位置抛出与断点相同类型的异常时挂起执行。

  • 不要忘记 异常断点在此异常的子类上挂起

    在异常的子类中挂起执行类型。

    例如,如果 RuntimeException 的异常断点被配置为在子类上挂起,它也将被一个 NullPointerException




An everyday debugging situation for Java developers is that in which an Exception is thrown and then you need to dig into the debugger to find out what threw it. Usually you would try to set up some breakpoints before the exception is thrown and hope that you are able to determine the situation that leads up to that exception.

In Eclipse, a breakpoint may have an expression defined where it is only triggered when, for example, variable x equals value y. My question is, is it possible to define some kind of global expression where, once an exception is thrown, it is caught by the debugger, allowing the programmer to inspect all variables immediately? Ideally you would not have hit the catch block yet, Eclipse would catch the exception being raised and stop execution without changing the stack contents.

Is this possible or is it limited by the JVM?

解决方案

Another illustration: Eclipse Tip: Breakpoint on Exception

Eclipse let you set breakpoints based on where an Exception occurs.
You access the option via the "j!" icon in the debugging window (i.e., in the "Breakpoint View").

The official help topic "Add Java Exception Breakpoint " has more on this.

  • The Uncaught Exception option is to suspend execution when an exception of the same type as the breakpoint is thrown in an uncaught location.
  • The Caught Exception option is to suspend execution when an exception of the same type as the breakpoint is thrown in a caught location.
  • do not forget the Exception Breakpoint Suspend on Subclass of this Exception:
    to suspend execution when subclasses of the exception type are encountered.
    For example, if an exception breakpoint for RuntimeException is configured to suspend on subclasses, it will also be triggered by a NullPointerException.

这篇关于在Eclipse IDE中调试Java时将异常作为表达式捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆