All of know the importance of the breakpoints during debugging. But do you know apart from setting a breakpoint on a line, there are other ways to set a breakpoint? Lets explore the breakpoints supported by Eclipse.

Line Breakpoint


This is the simplest breakpoint that everyone knows about. Double click the ruler and a breakpoint is set. Whenever that particular line is executed, the breakpoint is hit. If you want the breakpoint to be hit only certain conditions are met, then you can specify it in the breakpoint properties.

 

Line Breakpoing

Exception Breakpoint


When exceptions are passed over several layers, they are often wrapped or discarded in another exception. When you want to find out the origins of the original exception, then the Exception Breakpoint will help you. Once you add a breakpoint on an Exception (The action is available the Breakpoints view toolbar), the execution will be suspended whenever this Exception is thrown or caught.



Class Load Breakpoint


If you have troubles with classloading this might come handy. Double click the ruler in the line the class is defined. You will get a Classloading Exception. When the class is loaded, the breakpoint is triggered and you can inspect who is trying to load this class (or where is it used for the first time)



Watchpoint


You have a field, which is initialized to some value in the constructor. But during execution, you hit an NPE on that field. There are numerous places where it could have been changed and it would be a hard task to find all the places, set a breakpoint and then debug it. A Watchpoint on that field comes handy. You can break the execution not just the places where the field is modified, but also in the places where it is accessed. To add a watchpoint for a field, again double click the ruler on the line where it is declared.



Method Breakpoint


Not just fields, even methods can have a breakpoint. Again, double click the ruler, you get a method breakpoint. Now everytime this method is executed, the breakpoint will be hit. At a glance, this might sound like a useless thing, as you can always set a line breakpoint on the first line of a method. But this can break the execution even when the method exits. So if your method spans for 2000 lines with two dozen returns in there, this breakpoint is very useful to find out where and what is being returned from the method.



Printpoint


When you are able to reproduce a problem when running, but not debugging, then its potentially a race condition in a multithreaded app. Because you hit a breakpoint, you suspend that thread by default and the other threads might keep executing. It will be near to impossible to debug it and the only way to trace the race condition is to modify the code and insert sysout statements. Enter printpoint, you don't have to modify the code to do this. This is essentially a conditional breakpoint (either a Method Breakpoint or a Line Breakpoint), which has "return false" as the last statement in the condition. In this way, you get to execute the code in the condition clause, but don't have to break the execution. I wish I knew this feature when I was debugging a server bug in my previous job :-(

 

More articles :

» Extending FilteredItemsSelectionDialog

In a previous tip, you have seen various . One thing which was not explained in it was FilteredItemsSelectionDialog, as it deserves a tip on its own. In this tip, I'll explain how to extend that class.

» Selection Dialogs in Eclipse

If you are an Eclipse Plug-in developer, you must have used the MessageDialog. There are many other Dialogs provided by Eclipse Platform are reusable and part of the API. I'll try to explain the various selection dialogs that I know of. In case I've...

» Top 10 mistakes in Eclipse Plug-in Development

Having trained a lot of new comers to the Eclipse plug-in development, I've seen certain common mistakes repeated all the time. I've tried to compile a top 10 list of such common mistakes, so next time you hit them, you will know that you are not...

» Adding a new editorAction for Orion

In case you have not heard it yet,  is the new Web IDE from Eclipse. In a blog entry , I said that this one is going to stand out from the crowd and going to rule the world. Why can't the other Web IDEs do that? Because, Orion also would be walking...

» Remember the State

As a rule of thumb, your application should try to remember the state across sessions. So when a user hits the close button and then opens it after few mins/days, it should present exactly in the same way where he left. In this tip, I'm going to...

Subscribe To

Unless stated, all the text contents of this site is available under Eclipse Public License