Types of error

There are three types of error: syntax errors, logical errors and run-time errors. (Logical errors are also called semantic errors).

We discussed syntax errors in our note on data type errors. Since the development system cannot understand statements with syntax errors (just as you cannot understand sentences with grammatical errors), it is able to detect them as soon as you write them. The following subprogram has three syntax errors.

As you see, the syntax errors are indicated by a squiggly blue line. If you move the cursor over the blue line, the VB.NET development system displays an explanation of the syntax error, as shown below.

In this case, the error message states that the programmer has not created an object called "labelone." The programmer probably meant to type "label1".

In this case, the error message states that Labels do not have "Tuxt" properties -- the programmer probably meant to type "Text".

In this case, the programmer is attempting to assign a numeric (integer) value to a string property. The programmer probably meant to type "14".

Syntax errors are easy to find and correct because the development system finds them for you.

If you write a statement that is syntactically correct, the computer will understand and execute it. However, if you accidently told it to do something that you did not really intend, you would have made a logical or semantic error. For example, if a programmer accidently multiplies two variables when he or she meant to divide them, the program will give an incorrect result, but no error message.

Syntax errors are errors of grammar; whereas, logical or semantic errors are errors of meaning.

Run time errors are detected while the program executes. These are often discovered when the user enters illegal data. For example, if the user types in a string when the computer expects a number, there will be a runtime error:

When running a payroll program, the user entered "ten" instead of "10" for the hours worked. When the computer tried to multiply the pay rate by "ten", it generated the error message shown above.

Since the computer cannot generate an error message when you make a logical error, they are generally hardest to fix. Patiently stepping through the execution of the program will often help you find your error. We will also see debugging aids in the development system.


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.