Even the most experienced programmers make mistakes, and knowing how to debug an application and find those mistakes is an important part of programming.
Programming errors fall into three categories: compilation errors, run-time errors, and logic errors. The techniques for debugging each of these are covered in the next three lessons.
Compilation Errors
Compilation errors, also known as compiler errors, are errors that prevent your program from running. Most compiler errors are caused by mistakes that you make when typing code. For example, you might misspell a keyword, leave out some necessary punctuation, or try to use an End If statement without first using an If statement.
Run Time Errors
Run-time errors are errors that occur while your program runs. These typically occur when your program attempts an operation that is impossible to carry out.
An example of this is division by zero. Suppose you had the following statement:
Speed = Miles / Hours
If the variable Hours has a value of 0, the division operation fails and causes a run-time error. The program must run in order for this error to be detected, and if Hours contains a valid value, it will not occur at all.
When a run-time error does occur, you can use the debugging tools to determine the cause.
Logic Errors
Logic errors are errors that prevent your program from doing what you intended it to do. Your code may compile and run without error, but the result of an operation may produce a result that you did not expect.
For example, you might have a variable named FirstName that is initially set to a blank string. Later in your program, you might concatenate FirstName with another variable named LastName to display a full name. If you forgot to assign a value to FirstName, only the last name would be displayed, not the full name as you intended.
Logic errors are the hardest to find and fix, but debugging tools make this job easier, also.
Sunday, July 4, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment