Link Search Menu Expand Document

Errors

Table of contents

  1. Description
  2. Syntax Errors
  3. Runtime Errors
  4. Logic Errors

Description

The three types of errors we encounter while programming are syntax, runtime, and logic. Each of these errors are described below, along with a small example.

Syntax Errors

Syntax errors are caused by not following the rules of the language. Examples: beginning a variable name with a number, forgetting to close parenthesis or quotes, or misspelling keywords. The editor will usually bring these to your attention by underlining them in red.

Print('Hello there!')       # the *p* in print should not be capitalized

Runtime Errors

Runtime Errors happen during program execution and cause your program to crash. They are caused by asking the computer something it cannot do, such as division by zero or trying to access the 5th character of a four character string.

solution = 5 / 0            # division by zero is a fatal error

Logic Errors

Logic errors occur when the program runs fine, but the output is incorrect. This can be caused by incorrect algorithms, or mistyping an operator (ex: + instead of -).

total = subtotal - tax      # the subtraction operator should be addition