简体   繁体   English

检查Eclipse调试器中的当前异常?

[英]Inspect current exception in Eclipse debugger?

If a Java application throws an unhandled exception, it causes Eclipse to break at that point. 如果Java应用程序抛出未处理的异常,则会导致Eclipse在此时断开。 Is there a way to inspect the current exception? 有没有办法检查当前的异常? Basically, $exception from MSVS? 基本上,来自MSVS的$exception

In think the problem described occurs when making use of Exception breakpoint , in which case you don't have access to the exception variable and can't inspect it in the variables view. 在使用异常断点时会发生所描述的问题,在这种情况下,您无法访问异常变量,也无法在变量视图中对其进行检查。

I found a "solution" to this problem in the following post: Breakpoint at exception in Eclipse - how to examine Exception object? 我在下面的帖子中找到了这个问题的“解决方案”: Eclipse中的异常断点 - 如何检查异常对象?

It is: 它是:

There is an option in the Eclipse Preferences that allows inspecting of the thrown exception: Eclipse Preferences中有一个选项,允许检查抛出的异常:

Check Java -> Debug -> Open popup when suspended on exception 在异常暂停时检查Java - > Debug - > Open popup

With this option there will be a popup allowing inspection of the exception. 使用此选项,将有一个允许检查异常的弹出窗口。

Strange that this option is not checked by default as it is very useful ! 奇怪的是,默认情况下不会选中此选项,因为它非常有用!

If you want to inspect the Exception object, set up a breakpoint inside the catch block, or set up an Exception breakpoint, and hover over the variable while at the breakpoint. 如果要检查Exception对象,请在catch块内设置断点,或者设置Exception断点,并将鼠标悬停在断点处的变量上。

try {
    ...code...
} catch (Exception e) {
    ...
}

Hover over the e, or open the Eclipse Variables view and add the name of the exception variable. 将鼠标悬停在e上,或打开Eclipse Variables视图并添加异常变量的名称。

Hope this helps! 希望这可以帮助!

我通常转到'变量'视图并查找保存异常的变量(通常是e),但我认为它取决于发生异常的特定上下文,这不是您要求的Eclipse信息。

In the debug perspective of eclipse find the "Breakpoints" view. 在eclipse的debug透视图中找到“Breakpoints”视图。 Now find the tool bar icon with a little "J" and a "!", the tooltip for it should read "Add Java Exception Breakpoint". 现在找到带有“J”和“!”的工具栏图标,其工具提示应为“Add Java Exception Breakpoint”。 When you click this toolbar icon a window opens where you can type in an exception name and find the one you want. 单击此工具栏图标时,将打开一个窗口,您可以在其中键入例外名称并找到所需的名称。 Make sure that "Suspend on Uncaught Exceptions" is checked. 确保选中“暂停未捕获的例外”。 You may also want to uncheck "Suspend on Caught Exceptions" or you will probably suspend/break way to often on exceptions that are already handled appropriately in your code. 您可能还想取消选中“暂停捕获的异常”,或者您可能会在代码中已经正确处理的异常中暂停/中断。 Then click "OK". 然后单击“确定”。

You will now see your exception type in in the list of breakpoints and you can run your Java application in debug mode. 现在,您将在断点列表中看到异常类型,并且可以在调试模式下运行Java应用程序。 Eclipse will suspend/break on the uncaught exception and you can then debug and look at variables and such. Eclipse将暂停/中断未捕获的异常,然后您可以调试并查看变量等。 (Remember you can click on the call stack and look at other variables and methods) (记住你可以点击调用堆栈并查看其他变量和方法)

In the breakpoints list you can uncheck your exception type to no longer suspend/break on that particular exception. 在断点列表中,您可以取消选中异常类型,以便不再挂起/中断该特定异常。 This is convenient so you don't have to remove/add in typical exception types all the time. 这很方便,因此您不必一直删除/添加典型的异常类型。 You can imagine that I have NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsException, among others all added to my list and toggle them on/off as needed. 您可以想象我有NullPointerException,IllegalArgumentException,ArrayIndexOutOfBoundsException,以及其他所有添加到我的列表中并根据需要切换它们的开/关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Eclipse Debugger(for Java)中,有没有办法检查任意值? - In the Eclipse Debugger (for Java), is there a way to inspect arbitrary values? Eclipse:如何在自定义调试器中对源代码启用“监视并检查”操作? - Eclipse: How do I enable Watch and Inspect action on my source code in my custom debugger? Eclipse调试器总是在ThreadPoolExecutor上阻塞而没有任何明显的异常,为什么? - Eclipse debugger always blocks on ThreadPoolExecutor without any obvious exception, why? eclipse调试器-在特定位置引发异常时的断点 - eclipse debugger - breakpoint when exception is thrown on a specific place 在Eclipse中如何显示在显示窗口中执行的调试器代码的异常消息? - In eclipse how to show exception message of debugger code executed in display window? 检查悬停食 - Inspect on hover eclipse 无法在eclipse上检查变量 - Unable to inspect variables on eclipse Eclipse 调试器和远程调试器不工作 - Eclipse debugger and remote debugger not working 为什么Eclipse Debugger不会在范围异常断点处停止(如何在已处理异常处停止) - Why Eclipse Debugger does not stop on scoped exception breakpoint (how to stop on handled exception) 如何在没有sysouts的情况下在JRE(类似于eclipse中的调试器模式)中获取任何变量的当前值 - How to get the current value of any variable in JRE (Like debugger mode in eclipse) without sysouts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM