AP Computer Science Java: Lesson 1.1c
Java Basics - Programming Errors


Lesson 1.1c - Programming Errors
Purpose: To understand the three types of programming errors

Writing programs is a 3-step process:

1 - edit the program (the process of typing the code)
2 - compile the program (have the computer check over the program for correctness)
3 - execute the program (ask the computer to perform the steps of the program)

This multi-step process almost ensures that we will make a mistake, or error, at some point along the way. These errors fall into on of three categories: syntax errors, run-time errors and logic errors.

Syntax errors occur when we violate the rules of the language, no matter how minor. These errors are detected at compile time (when the computer checks our program to see if we have crossed our t's and dotted our i's). The compiler will give us messages to let us know where errors have occurred. However, as we have already seen, these error messages are sometimes cryptic.

Run-time errors occur when we ask the computer to do something it considers to be illegal. such as dividing by zero. For example, we may have an expression such as x / y which the compiler finds to be syntactically correct. Suppose the value of y is 0 at the time that this expression is executed. When the program tries to divide by 0, it will produce a run-time error message. Once again, these messages can sometimes be confusing.

Logic errors occur when we fail to express ourselves correctly. For instance, in everyday life we may tell someone to turn left when we meant to tell them to turn right. The instruction makes perfect sense and is understandable to the receiver of the instruction. However, it does not do what is intended, and is therefore logically incorrect. The bad news here is that the computer won't know when we make this type of error. We will be responsible for figuring out when and where they occur and how to fix them. This is the greatest challenge of computer programming. As a part of our study of java, we will learn how to prevent, detect and correct logic errors.

 

© DanShuster.com