Start with the recap, study the fully worked examples, then use the practice problems to
check your understanding of Error Types.
This page combines explanation, solved examples, and follow-up practice so you can move
from recognition to confident problem-solving in CS Thinking.
Concept Recap
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).
Some bugs stop the code from running, some crash it later, and some quietly give the wrong answer.
Read the first worked example with the solution open so the structure is clear.
Try the practice problems before revealing each solution.
Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea:Different bugs need different debugging strategies.
Common stuck point:Logic errors are often the hardest because the program still runs, so the bug is less obvious.
Sense of Study hint:Ask three questions: Does the code run at all? Does it crash while running? Does it run but give the wrong output? Your answer usually tells you the error type.
Common Mistakes to Watch For
Before you work through the examples, skim the mistake guide so you know which shortcuts and
sign errors to avoid.
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?
Example 4
hard
Trace the symptoms and classify: a function called once returns the right answer; called a second time it returns the previous answer concatenated with the new one because a list parameter has a mutable default `acc=[]`.
Practice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
easy
Classify this error: `print('hello'` (missing closing parenthesis).
Example 2
easy
Classify this error: dividing by zero, `x = 10 / 0`, which crashes mid-execution.
Example 3
easy
Classify this error: a function meant to add returns `a - b`, so the program runs but gives wrong answers.
Example 4
easy
Which error type does a compiler/interpreter typically catch BEFORE the program runs at all?
Example 5
easy
A program accesses `list[10]` on a list of length 5 and crashes. What error type is this?
Example 6
easy
A loop intended to run 10 times runs 9 times due to a wrong boundary, but the program does not crash. What error type?
Example 7
easy
Forgetting a colon after `if x > 0` in Python is which error type?
Example 8
easy
A program calls a function `compute()` that was never defined, causing a NameError when reached. What error type?
Example 9
medium
A program computes an average as `sum / count` but `count` is 0 for an empty list, crashing. Classify the error AND name the deeper category if the empty-list case was never considered.
Example 10
medium
Code: `if x = 5: print('yes')`. Identify the error type and the specific mistake.
Example 11
medium
A sort function returns a list that is reversed instead of sorted ascending. The code runs cleanly. Classify it and describe how to detect it.
Example 12
medium
A web form crashes when a user types letters into a number field. What error type, and what is the standard fix category?
Example 13
medium
Three bugs are found: (1) unmatched bracket, (2) accessing a null/None object, (3) a tax rate of 0.05 typed as 0.5. Classify each.
Example 14
medium
In Python, indenting one line of a block incorrectly causes 'IndentationError'. Which of the three main categories does this belong to?
Example 15
medium
A recursive function lacks a base case and runs until the program halts with a stack-overflow / RecursionError. Classify this.
Example 16
medium
A bank program computes interest correctly in testing but occasionally loses a cent due to floating-point rounding. Classify the error and explain why it is the hardest type to catch.
Example 17
challenge
You have one error and three suspects: a missing import (caught at run time), a `>` that should be `>=`, and a missing semicolon in C (caught at compile). A symptom: the program compiles and runs but excludes the boundary value. Which suspect is guilty and what type is it?
Example 18
challenge
Order these by how early they are typically caught (earliest first): logic error, syntax error, runtime error. Justify the order.
Example 19
challenge
A team reports 'the bug disappears when we add a print statement.' Which error type does this symptom most strongly suggest, and why?
Example 20
medium
Code: `total = total + 'x'` adds a string to a number, raising a TypeError when the line runs. Classify the error type.
Example 21
easy
Classify this error: `for i in range(10) print(i)` (missing colon after the for clause).
Example 22
easy
Classify this error: opening a file with `open('missing.txt')` when the file does not exist, raising FileNotFoundError as the program runs.
Example 23
easy
A function that should return the maximum of two numbers always returns the minimum. The program runs without crashing. Classify the error.
Example 24
easy
A user enters `'abc'` and the program calls `int('abc')`, which throws ValueError. Classify the error.
Example 25
easy
Classify: a Java program declares `int x = 'hello';` and the compiler refuses to build.
Example 26
easy
Classify: a program asks for two numbers and reports their average as their sum because the divide step was omitted.
Example 27
medium
A program prints leaderboard ranks 1, 2, 3, ..., 9, 10 but sorts strings, so the order is 1, 10, 2, 3, .... Classify and explain.
Example 28
medium
Classify each: (a) `x === 5` in Python, (b) accessing key 'name' in a dict that has only 'Name', (c) computing area as πr instead of πr2.
Example 29
medium
A program reads `int(input())` and the user types `3.5`, throwing ValueError. Is the deeper bug a logic error or only a runtime error?
Example 30
medium
An off-by-one in `for i in range(1, n)` causes the last element of an array of length n to be skipped. Classify the bug.
Example 31
medium
A program crashes on inputs of size > 1000 with MemoryError after building a list of all pairs. Classify and name the design-level cause.
Example 32
medium
Which error type is most likely to slip into production unnoticed for months: syntax, runtime, or logic? Justify in one sentence.
Example 33
medium
Classify: a Python program uses `True = 1` and the interpreter raises SyntaxError because `True` is reserved.
Example 34
medium
Classify: in JavaScript, `let x = 5; x = x + '1';` makes `x` equal to the string `'51'` instead of 6.
Example 35
medium
A web server crashes with `ConnectionResetError` when a client hangs up early. Classify and explain why the fix usually goes in error-handling, not the parser.
Example 36
medium
A test checks `assert factorial(5) == 120`. The code returns 60. Which error type is exposed by the failing assertion?
Example 37
medium
Classify: a SQL query has a missing comma between two columns and the database refuses to execute it.
Example 38
hard
A multi-threaded counter occasionally undercounts by 1 due to a race condition. Classify and explain why it is hard to detect.
Example 39
hard
A program parses cleanly but raises `UnboundLocalError: local variable 'x' referenced before assignment` only when a particular branch executes. Classify and explain the timing.
Example 40
hard
An image-resize function silently returns the original image when the requested size is 0. There is no crash. Classify the bug and propose where in the code base the fix belongs.
Example 41
hard
Sort by category: (a) missing `import math` (NameError when `math.sqrt` is called), (b) `if x < 0 print(x)` lacks the colon, (c) `return n*(n+1)//2 - 1` in a sum function.
Example 42
challenge
A long-running data pipeline produces correct results on small inputs and silently drops the last record on inputs whose size is a multiple of the batch size. Choose the most likely error type and the smallest reproducer you would build.
Example 43
challenge
You are handed three failure reports: (1) red squiggle in the editor before run, (2) intermittent crash under load, (3) wrong totals on the monthly summary. Pair each with syntax, runtime, or logic and rank by typical cost to fix in production.