2013-04-02 55 views
4

我有这样的功能:Eclipse条件断点。如何检查是否发生异常?

public static FradId readFradId(DataInput pIn) throws IOException { 
    Integer lMainId = Integer.valueOf(pIn.readInt()); 
    Integer lReferenceId = Integer.valueOf(pIn.readInt()); 
    String lShortname = pIn.readUTF(); 
    return new FradId(lMainId,lReferenceId,lShortname); 
    } 

我在这一行有一个断点:

String lShortname = pIn.readUTF(); 

我的问题是在某些情况下,功能readUTF抛出一个RuntimeException。该应用程序执行该功能超过100次,所以我很难找到问题。

我的问题:有没有办法用断点条件来捕获该异常?我已经在简单的布尔条件下使用了这些条件,但是当抛出异常时我不知道如何停止该行。提前

THX

斯特凡

+0

这就是为什么catch子句是存在的,在catch子句和你的方法发生断点应由尝试捕捉 – Pragnani

+0

我认为没有理由用一个try-catch包围它包围。我必须确定RuntimeException的原因。如果我在本课中加入try-catch,我会围绕真正的问题实施。当然,对于那个测试用例,我可以包含try-catch,但我希望这也可以通过条件断点实现。 –

回答

5

是的,有一个名为 “异常断点”
打开断点视图选项,点击j!选项并添加所需的异常

enter image description here

+0

这有效,但它可能会导致很多误报。当某个特定行或特定函数内抛出异常时,是否有办法打破? – z0r

+0

在这种情况下,您可以直接在该特定行上设置断点并检查异常是否继续 – xyz

1

你尝试类似的东西?

public static FradId readFradId(DataInput pIn) throws IOException { 
    Integer lMainId = Integer.valueOf(pIn.readInt()); 
    Integer lReferenceId = Integer.valueOf(pIn.readInt()); 
    try{ 
     String lShortname = pIn.readUTF(); 
    }catch(Exception e){ 
     //need a breakpoint here. 
    } 
    return new FradId(lMainId,lReferenceId,lShortname); 
} 
1

我想你需要Java Exception Break Point

在你日食打开'添加Java异常断点...'从运行菜单。你可以选择你需要有断点的异常。

Run -> Add Java Exception Breakpoint... 
相关问题