简体   繁体   English

如何设置Eclipse以阻止异常发生?

[英]How do I setup Eclipse to stop on the line an exception occurred?

How can I setup Eclipse to stop at the point an exception occurred. 如何设置Eclipse以在发生异常时停止。

I have an Eclipse breakpoint setup to break on an exception. 我有一个Eclipse断点设置来打破异常。 In the code example below, the problem I'm having is Eclipse tries to open the Integer source code. 在下面的代码示例中,我遇到的问题是Eclipse尝试打开Integer源代码。 Is there any way to just have debugger break at the point shown in my code example? 有没有办法让我的代码示例中显示的调试器中断? If I move down the stack trace, I will get to this line, it'd be nice if there's a way to do this without the "Source not found" window coming up. 如果我向下移动堆栈跟踪,我将到达这一行,如果有一种方法可以在没有“Source not found”窗口的情况下执行此操作,那就太好了。

This can be done in Visual Studio, so it's driving me crazy not being able to find a way to do this in Eclipse. 这可以在Visual Studio中完成,所以它让我疯狂,无法在Eclipse中找到这样做的方法。

package com.test;

public class QuickTest
{
  public static void main(String[] args)
  {
    try
    {
        test();
    }
    catch(NumberFormatException e)
    {
        System.out.println(e.getMessage());
    }
 }

  private static void test()
  {
    String str = "notAnumber";

    Integer.parseInt(str);//<----I want debugger to stop here
  }
}

I'm not sure how else to get there, but I just do: 我不知道怎么去那里,但我只是这样做:

Window -> Show View -> Breakpoints

And in that tab there is a "J!" 在那个标签中有一个“J!” that lets you set breakpoints on exceptions. 允许您在异常上设置断点。

Preferences -> Java -> Debug -> Step Filtering Choose packages you want to filter out when debugging (java.*, sun.*, etc) On debug make sure the little step filtering arrow is selected. 首选项 - > Java - >调试 - >步骤过滤选择要在调试时过滤掉的包(java.*, sun.*, etc)在调试时确保选中了小步过滤箭头。

This should do the trick. 这应该可以解决问题。

  1. Can't you just set a breakpoint on the Integer.parseInt(str) line? 你不能只在Integer.parseInt(str)行设置一个断点吗?
  2. If you point your Eclipse project at using a JDK instead of a JRE it should pick up the source code for all of the platform classes (Integer etc). 如果您将Eclipse项目指向使用JDK而不是JRE,那么它应该选择所有平台类(Integer等)的源代码。

The Debug view will show the entire stack of the current execution. Debug视图将显示当前执行的整个堆栈。 You need to select the line you want to see. 您需要选择要查看的行。 It will be same as you had a breakpoint there, you can see all the variables etc. 它会与你在那里有一个断点相同,你可以看到所有的变量等。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM