如何设置 Eclipse 以在发生异常时停止?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2471425/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:32:43  来源:igfitidea点击:

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

javaeclipsedebuggingexception

提问by Chris Persichetti

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. In the code example below, the problem I'm having is Eclipse tries to open the Integer source code. 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.

我有一个 Eclipse 断点设置来中断异常。在下面的代码示例中,我遇到的问题是 Eclipse 试图打开 Integer 源代码。有没有办法让调试器在我的代码示例中显示的点中断?如果我向下移动堆栈跟踪,我将到达这一行,如果有一种方法可以在不出现“找不到源”窗口的情况下执行此操作,那就太好了。

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
  }
}

 

 

回答by job

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!" that lets you set breakpoints on exceptions.

在那个标签中有一个“J!” 这让您可以在异常上设置断点。

回答by Dark Castle

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.

Preferences -> Java -> Debug -> Step Filtering 选择你想(java.*, sun.*, etc)在调试时过滤掉的包在调试时确保小步过滤箭头被选中。

This should do the trick.

这应该可以解决问题。

回答by matt b

  1. Can't you just set a breakpoint on the Integer.parseInt(str)line?
  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).
  1. 不能直接Integer.parseInt(str)在行上设置断点吗?
  2. 如果您将 Eclipse 项目指向使用 JDK 而不是 JRE,它应该选择所有平台类(整数等)的源代码。

回答by saugata

The Debug view will show the entire stack of the current execution. 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.

调试视图将显示当前执行的整个堆栈。您需要选择要查看的行。它将与您在那里有一个断点相同,您可以看到所有变量等。