Java Reference
In-Depth Information
but not an uncommon one when designing a loop that keeps track of the processing
state. To fix it, stop the debugger and add the following clause:
if ("aeiouy".indexOf(ch) >= 0)
{
. . .
}
else insideVowelGroup = false;
Now recompile and run the test once again. The output is:
A debugger can be used only to analyze the presence of bugs, not to show that a
program is bug-free.
Syllables in hello: 2
Syllables in yellow: 2
Syllables in peach.: 1
Is the program now free from bugs? That is not a question the debugger can answer.
Remember: Testing can show only the presence of bugs, not their absence.
S ELF C HECK
13. What caused the first error that was found in this debugging session?
14. What caused the second error? How was it detected?
272
273
H OW T O 6.2: Debugging
Now you know about the mechanics of debugging, but all that knowledge may still
leave you helpless when you fire up a debugger to look at a sick program. There
are a number of strategies that you can use to recognize bugs and their causes.
Step 1 Reproduce the error.
As you test your program, you notice that your program sometimes does
something wrong. It gives the wrong output, it seems to print something
completely random, it goes in an infinite loop, or it crashes. Find out exactly how
to reproduce that behavior. What numbers did you enter? Where did you click with
the mouse?
Search WWH ::




Custom Search