Error Types Formula

Error types are the main categories of mistakes that can occur in a program.

The Formula

errors={syntax,runtime,logic}

Ask yourself: Is the job to label a mistake as one that stops the code starting, crashes it partway, or gives a wrong answer?

Quick example

Missing a closing bracket is a syntax error. Dividing by zero can cause a runtime error. Using the wrong formula creates a logic error.

What this formula means

Error types are the main categories of mistakes that can occur in a program. The most common categories are syntax errors (the code is written incorrectly), runtime errors (the program crashes while running), and logic errors (the program runs but gives the wrong answer).

Error types are like mistakes in a recipe. A smudged line nobody can read is a syntax error: the cook cannot use the recipe. 'Add the eggs' when there are no eggs is a runtime error: cooking stops partway. 'Bake at 400 °C' instead of 200 °C is a logic error: every step is done exactly as written, and the cake is ruined.

Formal view

Programming errors are commonly classified as syntax violations caught by the parser, runtime failures triggered during execution, and logic defects that preserve execution but violate correctness.

Worked examples

Example 1

medium
Trace and classify: `def avg(xs): return sum(xs)/len(xs)` is called as `avg([])`. What error fires and what category?
Show solution

Answer

runtime error (ZeroDivisionError)

First step

1.
`len([])` is 0.

See the full worked solution + why-it-works coaching

SetupKey insightWhy it worksCommon pitfallConnection

Free: full solutions on 3 topics a day. No card.

Every topic, every day: the Family plan

Example 2

medium
Trace: `def f(x): return x/0`. Is `f` flawed at parse time, call time, or only when called with certain inputs?

Example 3

medium
Trace: `nums=[3,1,2]; nums.sort; print(nums[0])`. Is anything wrong, and if so what type?

Common mistakes

  • Calling every wrong answer a syntax problem even when the code runs
  • Fixing one runtime crash without checking whether a deeper logic problem remains
  • Ignoring compiler or interpreter messages that already identify the error category

Common mistakes guide

If this formula keeps breaking in real problems, read the most common errors before you practice again.

Why this formula matters

Each type needs a different search: syntax errors are found by reading the error message, runtime errors by finding the input that triggers the crash, and logic errors only by testing against known answers. Logic errors are the dangerous ones. A grade calculator that averages wrongly still prints a neat, believable number, and nobody notices until someone checks by hand.

Frequently asked questions

What is the Error Types formula?

Error types are the main categories of mistakes that can occur in a program. The most common categories are syntax errors (the code is written incorrectly), runtime errors (the program crashes while running), and logic errors (the program runs but gives the wrong answer).

How do you use the Error Types formula?

Use error types when you have to classify a problem in a program from an error message, a crash, or an output that is simply wrong. Clues: 'SyntaxError' or 'won't start' point to syntax; 'division by zero' or 'index out of range' partway through point to runtime; 'runs but the total is wrong' points to logic. Once the type is named, finding and fixing the actual line is Debugging. Choosing the inputs that reveal errors is Testing.

Why is the Error Types formula important in CS Thinking?

Each type needs a different search: syntax errors are found by reading the error message, runtime errors by finding the input that triggers the crash, and logic errors only by testing against known answers. Logic errors are the dangerous ones. A grade calculator that averages wrongly still prints a neat, believable number, and nobody notices until someone checks by hand.

What do students get wrong about Error Types?

Logic errors are often the hardest because the program still runs, so the bug is less obvious.

What should I learn before the Error Types formula?

Before studying the Error Types formula, you should understand: debugging.