11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10Debugging C++In This Chapter Differentiating the types of errors Understanding “crash messages” Choosing the WRITE statement debugging technique Mastering the debugger toolYou may have noticed that your programs often don’t work the first time.In fact, I have seldom, if ever, written a nontrivial C++ program that didn’thave some type of error the first time I tried to execute it.That leaves you with two alternatives: You can give up on programming nowwhile you still have a chance, or you can find and fix your errors. This chapterassumes you’ll use the latter approach. In this chapter, you find out howto track down and eradicate software bugs.Identifying Types of ErrorsTwo types of errors exist — those that the C++ compiler can catch on its ownand those that the compiler can’t catch. Errors that C++ can catch are knownas compile-time errors. Compile-time errors are relatively easy to fix becausethe compiler generally points you to the problem. Sometimes the descriptionof the problem isn’t quite correct. Sometimes the description isn’t even close(it’s easy to confuse a compiler), but after you learn the quirks of your ownC++ environment, understanding its complaints isn’t too difficult.Errors that C++ can’t catch show up as you try to execute the program. Theseare known as run-time errors. Run-time errors are harder to find than compiletimeerrors because you have no hint of what’s gone wrong except for whatevererrant output the program might generate. “Errant” being the key wordhere.You can use two different techniques for finding bugs. You can add outputstatements at key points. You can get an idea of what’s gone wrong with your

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!