How to stop Eclipse from breaking at every caught exception? - java

When I start debugging a java project, Eclipse keeps on breaking at random exceptions in 3rd party libraries, and it's so annoying.
any idea how to stop this?
I tried clicking on the (!) icon on the Breakpoints view, I can see that both "Suspend on caught exceptions" and "Suspend on uncaught exceptions" checkboxes are not checked.. still Eclipse breaks on the exception.
Although I'm not sure I'm using this window correctly, am I meant to select the exceptions one by one? Or is there a way to specify all exceptions?

I had a similar issue with Eclipse stopping on uncaught exceptions and resolved it by going to Window - Preferences - Java - Debug and unchecking "Suspend execution on uncaught exceptions".
[Note: Not an answer to the exact question asked but highly related].

The exceptions you select with the "!" icon in the Breakpoint view are the exceptions you want to stop on. If you put "NullPointerException" in there and tell Eclipse to stop on "Caught and uncaught", your execution will stop on every last NullPointerException that gets thrown. Are you sure you haven't set a breakpoint on each of the "random exceptions" your execution stops on?

Related

Debugging some code that is not printing any stack trace

So I am debugging someone else's customized code used in a Java based enterprise software. As per his documentation, a specific file has the customization I am looking into. I deployed all customized files on the test server and now the browser window crashes as soon as it starts to render data using that code. No stack trace gets printed out. The customized code in question is not actually causing the issue. The issues is caused by some other code that uses the data returned from this piece of code. The puzzle for me is that I don't really know where the data is being returned to, and any error being thrown is not printed out. Is there anything I can do to figure out what file uses the data returned by this customized code?
Brute force: Tell debugger to break on all exceptions.
E.g. in Eclipse, select menu "Run" > "Add Java Exception Breakpoint...", type Exception and select the java.lang.Exception, check both "Suspend on caught exceptions" and "Suspend on uncaught exceptions", and click "OK". In the "Breakpoints" view, select the new Exception breakpoint and check "Subclasses of this exception".
This is break on any thrown Exception (not Error). You may see a lot of false positives, which is why I call this the "brute force" method.
Change to Throwable if you want to catch Error too.

How to specify a custom action on Java exception in Eclipse IDE?

I'm working in Java with Eclipse (Luna) and I would like to specify what action happens whenever my project throws an exception. In other words, anytime an error happens and Eclipse prints a stack trace to the console, I would like to run my own code to print the stack trace in my own debug window or save to a text file, for example.
I'm not sure if this is a problem for my java project (maybe by overriding printStackTrace()?) or for the IDE itself (through some setting, etc.) Either way it doesn't really matter since its just a debug feature and would be removed before I export anything public.
Thanks for your help
EDIT: To clarify, I'm not talking about exceptions only from a specific line/class. I'm familiar with try-catch blocks. What I want is to preform an action any time any exception or error happens anywhere in my code, even if there is a typo and my project wont compile.
NOTE: You cannot have your own debug window in IDE
If you want to log some of your exceptions to some file wherein latter on you can see, so its time you use log4j.
Start with this simple example.
You will find ample on google :)

Stop eclipse switch to Debug tab

My problem is somewhat like the question here and here, but none of those answer can apply to my situation.
I am running tomcat inside Eclipse, and my project has some quartz job that run by schedule. Those quartz job meets null pointer exception very often (since they must parse documents from an untrusted source) and surely the team who are working with those jobs can't fix them right away.
The result is that Eclipse pop up debug tab every now and then, usually take up focus so that I can't look what happen in console. Moreover, when Eclipse meet the exception, it pop out to take focus out of the program I currently work in (browser, email,...). It is very annoying.
Can I simply skip all the null pointer exceptions (since the fail of the jobs doesn't affect my program anyway) or is there a way to keep the focus on the console tab, and keep Eclipse doesn't complain everytime an exception pop out?
I'm very thankful for any possible solution.
UPDATE: I'm using Eclipse Helios with few plugins.
Have you looked in Eclipse's settings under Run/Debug? There are two useful options you can change;
Activate the workbench when a breakpoint is hit
Activate the debug view when a breakpoint is hit
Another obvious option would be to not use debug mode and "run" the application instead (AFAIK, breakpoints will never stop execution when "Running" code instead of "Debugging" it).
Window > Preferences > Run/Debug > Perspectives >
> Open the associated perspective when an application suspsends:
Set to Never, or Prompt (as desired)
It sounds like you have an unwanted Breakpoint set up in your Workspace. Open up your Breakpoints view, and you should see a breakpoint listed as a NullPointerException, RuntimeException or Exception. Uncheck it.
If you want to suspend the thread for all other occurences of NullPointerException, then you could look into Conditional Breakpoints (i.e. right-click on the breakpoint in the BreakPoints view, and click on Properties. You'll see a dialog with options for 'Conditional breakpoints'). That should set you on your way.
Edit: here's another possibility. Try looking in the Java Debug preferences:
Menu > Window > Preferences
Then choose:
Java > Debug
Now uncheck an option called:
Suspend execution on uncaught exceptions

Programs in netbeans do not terminate as they are done with execution but continue running on as "Running Tasks"

My programs in netbeans do not terminate as they are done with execution but continue running on as Running Tasks appearing at the right bottom corner of the netbeans window. Each time I re-run my same program a new thread is added to the 'Running Tasks' even when the code is done with execution.
Why is this caused ?
How can I rectify this ?
This is an extremely old question but I stumbled upon this having the same issue. Here is how I solved it:
Close NetBeans, delete the NetBeans folder from C:\Users\[your username]\AppData\Roaming\, then restart NetBeans. WARNING: this will delete any specific settings you've set (i.e. font size/style, etc) so beware of that before trying this
It seems one of the User Thread is running, post code to get the exact answer
Your programming is not exiting correctly. If it is a GUI make sure your main Frame is set to Exit on close, or that at least something is set to exit when the frame is closed.

eclipse debug stop on error line

In Visual studio when an error happens during debug, the line causing the error is jumped to in the source code and the error displayed.
Is there a way with Elcipse to do the same? The Debug perspective appears, but the line causing the error and the error message are not immediately apparent.
I'm assuming you are working with Java, so the answer is yes. You can tell Eclipse to break on exception. From the Run menu, select Add Java Exception Breakpoint.... Now, you need to select the Exception class. If you wish to stop on all Exceptions, you can use java.lang.Throwable. You can also specify whether to stop on caught or uncaught exceptions.
You can (and should) also use it for assertions, as I outlined in this post.

Categories

Resources