In this section we discuss how to use breakpoints to pause your application while you examine control properties and variable values.
A breakpoint is a position in the logic of your code where you’d like to stop everything and conduct an inspection. Some programming constructs can get quite complicated, so it’s useful to say, “Halt!” and then review the current status of one or many variables. Breakpoints allow you to do just that—pause and take a look.
To create a breakpoint, simply double-click a line number in your code editor where you want to suspend your application. To test this, we’ll create two breakpoints, one inline with
doAdd() and the other inline with
doMultiply(); see Figure 6-3. We’ll also need to restore the
change method of our
NumericStepper to call
onChange() once again, shown in Example 6-7.
Figure 6-3. Breakpoints created to interrupt the two math functions in DebugApp
Example 6-7. Restoring the onChange() function to test breakpoints
Breakpoints will stop your application before any code on that line is processed. Therefore, it’s best to place breakpoints on the same line calling a function so you can inspect variable values both before and after they are changed by a problematic routine.
At this point, you’re ready to launch the application in Debug mode. Whenever the ...