4

I have this function:

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

I got a breakpoint at this line:

String lShortname = pIn.readUTF();

my problem is in some cases the function readUTF throws a RuntimeException. The application executes the function more than 100 times so it is very difficult for me finding the problem.

my question: is there a way to catch that exception with a breakpoint condition? I already use that conditions with easy boolean conditions, but I dont know how to stop in that line when a exception is thrown.

Thx in advance

Stefan

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
nano_nano
  • 12,351
  • 8
  • 55
  • 83
  • That why catch clause is there, place break point in catch clause and your method should be surrounded by try catch – Pragnani Apr 02 '13 at 07:34
  • I see no reason to surround it with a try-catch. I have to determine the reason for the RuntimeException. If I include the try-catch in this class I would implement around the real problem. Sure for that one testcase I could include the try-catch but I hope that this is also possible with a conditional breakpoint. – nano_nano Apr 02 '13 at 07:37

3 Answers3

8

Yes there is a option called "exception breakpoint"
Open Breakpoint view, click on j! option and add desired exception

enter image description here

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
  • That works, but it can result in a lot of false positives. Is there a way to break when an exception is thrown by a certain line, or within a certain function? – z0r Jun 05 '14 at 05:11
  • in such case you can directly set breakpoint on that particular line and check if exception is thrwon or not – Ajinkya Jun 05 '14 at 05:24
2

I think you need Java Exception Break Point

In you eclipse open the 'Add Java Exception Breakpoint...' from Run Menu. You can chose the exception for which you need to have the breakpoint.

Run -> Add Java Exception Breakpoint...
Jayamohan
  • 12,734
  • 2
  • 27
  • 41
1

did you try something similar?

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);
}
guness
  • 6,336
  • 7
  • 59
  • 88