Skip to content, Skip to search


Debugging Exercises

104 bytes added, 13:01, 3 December 2015
Exercise 3: Conditional breakpoints
Using <code>count</code>-based conditional breakpoints can be very useful if the error is deterministic. In this case we need to try something different. We know the <code>everythingIsOK</code> flag reflects the integrity of the object at a given index - so what we really want to use here is a breakpoint that stops in the loop when the <code>everythingIsOK</code> flag is set to '''false'''. Fortunately, breakpoints have an optional "Conditional" flag - where we can enter any Java statement that resolves to a boolean value. Try it out:
[[File:E3ConditionalBreakpoint.png|350px|right|thumb|Setting a conditional expression]]
# Uncheck the ''Hit Count'' box
# Check the ''Conditional'' box, and "Suspend when 'true'"
# Enter the condition we want to check (any Java conditional statement can be used here)
# Try debugging again
Were you able to get the breakpoint to stop in the loop only when a problem is encountered?
Bureaucrat, emailconfirmed, incoming, administrator, uploaders