Conditional breakpoints are breakpoints that suspend code and open the debugger only when certain conditions are met. For example, you can set a breakpoint to suspend code only if a variable's value falls in a particular range of values.
To set conditions on a breakpoint, right-click on the breakpoint symbol , and select Modify
from the pop-up menu.
In the dialog that appears, enable the On expression checkbox. Then you can select a condition from the drop-down list, or you can type in your own condition. (The drop-down list contains up to ten conditions you have previously set on breakpoints). If the condition is evaluated to a boolean value of true, then the breakpoint suspends the code and opens the Debugger browser.
Example: "Using a conditional breakpoint"
Configuring the breakpoint to do something
Similarly, you can configure a breakpoint to run a Java statement and then return
true or false. For example, when the IDE encounters the breakpoint, you can have it
output a message and then evaluate to false, thereby not suspending the code.
The text entry field in the dialog has code assist support; if you type in the start of a package or class name, press Ctrl+Spacebar to get a pop-up list of available classes or methods. Select the desired one by continuing to type or by using the arrow keys, and press Enter.
Example: "Configuring a breakpoint to print a message"
Other conditional breakpoint settings
Similarly, you can set a breakpoint to halt execution only when encountered from
a particular thread, or only on a particular iteration in a program.
Suppose you have two threads running, and both call a method, getAValue(), on which you've set a breakpoint. When the first thread encounters the breakpoint, go to the Breakpoints page and right click on the breakpoint. Select Modify. Enable the In selected thread checkbox and select the desired program and thread.
Likewise, if you want to break on a particular iteration in a loop, enable the On iteration checkbox and input the desired iteration.
The effect of these three conditions (thread, expression, and iteration) are cumulative. For example, if you have selected a thread 'A' and iteration 3, execution will break on the third iteration of the loop on thread 'A', but will ignore occurrences on other running threads.
Setting breakpoints in source code
Clearing and disabling breakpoints