11.4. Program Debugging

The best way to solve program debugging is to never write a program with a bug in it. Since that's probably not going to happen anytime soon, your next best approach is to know how to use a program debugger effectively. Although you can write C# program code in other environments, I assume you are using Visual Studio. However, most of the debugging techniques discussed here apply to any programming environment.

11.4.1. The Nature of the Beast

I've already discussed syntax and semantic errors and how they are different from one another. Logic errors are the third type of program error, or bug, and it is this type of error I want to examine here. There are three steps in fixing a program error: 1) detection, 2) isolation, and 3) correction.

11.4.1.1. Detection

Strange as it sounds, detecting a program error isn't as easy as it might seem. If it were, no program would ever be released to the public with an error in it. For example, my company produced a statistics package named Microstat, which we sold for over 20 years. After almost seven years in the field with thousands of users, the Stepwise Multiple Regression component failed on one particular data set. The problem was caused when US Gross National Product (GNP) was entered in dollars and the program was calculating the sums of squares of cross products. The GNP data set was sufficiently large that the sums of squares overflowed the range of a floating-point number. (Floating-point values for the language ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.