Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

How can I setup Eclipse to stop at the point an exception occurred.

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.

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.

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

 

like image 747
Crispy Avatar asked Mar 18 '10 16:03

Crispy


People also ask

How do I fix Java exception breakpoint in eclipse?

You can fix this immediately by opening the Markers view and delete the Java Exception Breakpoints. However, to permanently remove this type of breakpoints, you have to go to the Java Debug options and uncheck the "Suspend excecution on uncaught exceptions" option.

What is line breakpoint in eclipse?

A breakpoint is a signal that tells the debugger to temporarily suspend execution of your program at a certain point in the code. To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position.

What is Eclipse run to line?

Select a specific line of code (from Eclipse) and stop your program when that line is executed. The Run to Line function in the context menu allows you to select a line in the editor, and perform a Run to Line operation to this location.


2 Answers

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.

like image 146
job Avatar answered Oct 01 '22 18:10

job


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.

This should do the trick.

like image 34
Dark Castle Avatar answered Oct 01 '22 17:10

Dark Castle