Know Your Bugs: Three Kinds of Programming Errors

In this lesson, you will learn about the different types of errors that can occur when writing a program.

Even the most experienced programmers make mistakes, and knowing how to debug an application and find those mistakes is an important part of programming. Before you learn about the debugging process, however, it helps to know the types of bugs that you will need to find and fix.

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. When you press F5 to run a program, Visual Basic compiles your code into a binary language that the computer understands. If the Visual Basic compiler comes across code that it does not understand, it issues a compiler error.

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.

Fortunately the Visual Basic Code Editor was designed to identify these mistakes before you try to run the program. You will learn how to find and fix compilation errors in the next lesson, Finding and Getting Rid of Compiler Errors.

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 in Visual Basic to determine the cause. You will learn how to find and fix run-time errors in the lesson It Doesn't Work! Finding and Eliminating Run-Time Errors.

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 Visual Basic has debugging tools that make this job easier, also. You will learn how to find and fix logic errors in What? It Wasn't Supposed To Do That! Finding Logic Errors.

Next Steps

In this lesson, you learned about the three categories of programming errors. In the next lesson you will learn about debugging compiler errors.

Next Lesson: Finding and Getting Rid of Compiler Errors

See Also

Tasks

Finding the Errors: Introduction to Visual Basic Debugging

Other Resources

What Went Wrong? Finding and Fixing Errors Through Debugging