3.6. Runtime Errors

The second type of error is a runtime error. A program with a runtime error is one that passed the interpreter’s syntax checks, and started to execute. However, during the execution of one of the statements in the program, an error occurred that caused the interpreter to stop executing the program and display an error message. Runtime errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened.

Here are some examples of common runtime errors you are sure to encounter:

The following program contains various runtime errors. Can you spot any of them? After locating the error, run the program to see the error message.

Notice the following important differences between syntax errors and runtime errors that can help you as you try to diagnose and repair the problem:

Stay tuned for more details on the various types of runtime errors. We have a whole section of this chapter dedicated to that topic.

Check your understanding

You have attempted of activities on this page