Sometimes you want your breakpoint to be triggered when the line is triggered n times. For example, you have a loop and you are interested in inspecting your application only when the counter hits 50, then you use the Hit Count option of the breakpoint. Also sometimes, as I have already mentioned, one line can be called hundreds of times, and if you want to explore a particular situation, you just set your Hit Count
to the number at which the breakpoint should be triggered. Thus, the debugger will skip the breakpoint n times and trigger on the count you specified.
Please terminate the debugger if it is still running, remove Printpoint that we have set up in the previous example, and uncomment line 113.
andrew.setPosition("programmer"); andrew.setPosition("employee");
We need it so that we can call one function several times.
if
statement of setPosition()
) and set a breakpoint.3
as shown in the following screenshot:If you did everything correctly, your program should stop at line 31. Take a look at the Debug view. Your stack shows that setPosition()
was called by the main()
method on line 114. Line 114 is the third occurrence of the setPosition()
function, which means that the two previous occurrences were skipped.
Imagine if we do not put the Hit Count breakpoint, then the breakpoint would be triggered for the second and third time. But because we have set Hit count to 3
, the breakpoint was triggered only on the third occurrence and simply finished execution.
Now you know how the Hit Count breakpoint works. Please delete lines 113 and 114 that we have added specifically for this example. Also unset the Hit Count breakpoint and terminate the debugger before we move to the next recipe.
52.15.80.101