Making a Breakpoint Conditional

When you make a breakpoint conditional, the debugger pauses when a certain condition is met. When a breakpoint is first set, the debugger pauses the program execution each time the breakpoint is encountered. However, using the Edit Breakpoints dialog, you can customize breakpoints so that they are activated only in certain conditions.

The Conditions tab in the Breakpoint dialog is where you enter an expression that is evaluated each time the debugger encounters the breakpoint while executing the program. If the expression evaluates to true, then the breakpoint pauses the program. If the condition evaluates to false , then the debugger does not stop at that breakpoint location.

For example, suppose you want a breakpoint to pause on a line of code only when the variable mediumCount is greater than 10.

To set a breakpoint condition:

  1. Set a breakpoint on a line of code by clicking to the left of the line in the Source Editor.
  2. Open the Breakpoints window by choosing V iew then choose Debug Windowsthen choose Breakpoints.
  3. In the Breakpoints window, right-click the breakpoint you just set and choose Edit Breakpoint.
  4. In the Edit Breakpoints dialog, click Conditions .
  5. Enter an expression in the Condition field, for example:
    mediumCount > 10
  6. Click OK.

You can enter any valid Java language expression in the Edit Breakpoint dialog, but all symbols in the expression must be accessible from the breakpoint's location, and the expression cannot contain any method calls. For an exception breakpoint, you may want to use the exception object in your condition by using _throw.

Using Pass Count Breakpoints

The Pass Count field specifies the number of times that a breakpoint must be passed for the breakpoint to be activated. Pass counts are useful when you think that a loop is failing on the nth iteration. The debugger pauses the program the nth time that the breakpoint is encountered during the program run. The default value is 1.

If the Pass Count column is shown in the Breakpoints window, you can see the pass count value decrement each time the breakpoint line of code is encountered during the program execution. If the pass count equals 1 when the breakpoint line is encountered, the breakpoint is activated, and the program pauses at that line.

When pass counts are used together with breakpoint conditions, the breakpoint pauses the program execution the nth time that the condition is true; the condition must be true for the pass count to be decremented.


Related topics
About Breakpoints
Setting Source Breakpoints
Using Acceptable Legal Java Expressions in the Debugger