Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C++ For Dummies (2004) [eng].pdf
Скачиваний:
84
Добавлен:
16.08.2013
Размер:
8.09 Mб
Скачать

Chapter 10

Debugging C++

In This Chapter

Differentiating the types of errors

Understanding “crash messages”

Choosing the WRITE statement debugging technique

Mastering the debugger tool

You 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’t

have some type of error the first time I tried to execute it.

That leaves you with two alternatives: You can give up on programming now while you still have a chance, or you can find and fix your errors. This chap­ ter assumes you’ll use the latter approach. In this chapter, you find out how to track down and eradicate software bugs.

Identifying Types of Errors

Two types of errors exist — those that the C++ compiler can catch on its own and those that the compiler can’t catch. Errors that C++ can catch are known as compile-time errors. Compile-time errors are relatively easy to fix because the compiler generally points you to the problem. Sometimes the description of 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 own C++ environment, understanding its complaints isn’t too difficult.

Errors that C++ can’t catch show up as you try to execute the program. These are known as run-time errors. Run-time errors are harder to find than compiletime errors because you have no hint of what’s gone wrong except for what­ ever errant output the program might generate. “Errant” being the key word here.

You can use two different techniques for finding bugs. You can add output statements at key points. You can get an idea of what’s gone wrong with your