Conditional debug point setting is the most effective debugging technique which is also the most ignored one. This technique is often ignored due to not knowing how powerful it can be.
Let us continue with our previous example of a for loop with 1000 elements. Only difference being, our code is not throwing any exception this time, but producing erroneous result. How can we find out the issue?
Obviously, we don’t want to execute the for loop one item at a time for 1000 times. What is the way out then? Is there any way to trick the debugger to suspend execution just for the item in the list you want?
Conditional debugging is just the feature we need. Conditional breakpoints allow us to write an expression using the variables in scope at the position we are adding the breakpoint. The expression must evaluate to a Boolean type. Debugger evaluates the expression each time runtime hits the line number. But, execution is suspended only if the expression evaluates to true.
Now you must be convinced that conditional breakpoint is a powerful tool. Let me show you how conditional breakpoints are set. Suppose our code for calculating average salary is not working correctly for Java developers. Therefore, instead of inspecting each developer instance in list of developers we want to suspend breakpoint only for Java developers.
Right click on the breakpoint already set at the line where you want to add condition. From the context menu displayed, select ‘Breakpoint Properties’ option as shown below.