AP CSP Topic 1.4: Identifying and Correcting Errors

Learn to find and fix bugs—master error types, debugging techniques, and testing strategies for the AP exam.

📘 Big Idea 1: Creative Development

Bugs happen to everyone. This guide teaches you to identify error types, use systematic debugging techniques, and create effective test cases—essential skills for the AP CSP exam and Create Task.

🐛 Four Types of Errors

📝

Syntax Error

Language rules not followed. Program won't run.

x = 5 +
// Missing operand
🧠

Logic Error

Algorithm is flawed. Runs but gives wrong results.

average = a + b / 2
// Should be (a+b)/2
💥

Runtime Error

Crashes during execution. Runs, then fails.

result = 10 / 0
// Division by zero
📊

Overflow Error

Number exceeds storage range. Value wraps or fails.

// 8-bit max: 255
value = 255 + 1 → 0

🎯 Spot the Error

Identify the error type in each code snippet:

Snippet 1: Check if number is positive
IF number > 0
  DISPLAY "Negative"
ELSE
  DISPLAY "Positive"
Logic Error: The messages are swapped. When number > 0, it should display "Positive", not "Negative".
Snippet 2: Calculate area
area = length * width
DISPLAY "Area is: " area
Syntax Error: Missing concatenation operator between the string and variable. Should be "Area is: " + area or similar.
Snippet 3: Get list item
myList = [10, 20, 30]
item = myList[5]
Runtime Error: Index 5 is out of bounds—the list only has 3 items (indices 0, 1, 2). This crashes during execution.

🔧 Debugging Techniques

🛠️ Debugging Playbook

  • Test Cases: Run with known inputs, compare actual vs expected outputs
  • Hand Tracing: Step through code manually, track variable values on paper
  • Visualizations: Use diagrams or tools to see data flow and state changes
  • Debuggers: Set breakpoints, step through code, inspect variables in real-time
  • Print Statements: Add output to show variable values at key points

Error rate can help track debugging progress: \( \text{ErrorRate} = \frac{\text{failed tests}}{\text{total tests}} \times 100\% \)

✅ Testing for Correctness

Good test cases cover multiple scenarios. Include boundary tests: \( x_{\min}, x_{\max}, x_{\min}-1, x_{\max}+1 \)

📋 Test Case Categories

  • Typical inputs: Normal, expected values
  • Boundary values: Minimum and maximum allowed
  • Just beyond boundaries: One less than min, one more than max
  • Edge cases: Empty inputs, zero, negative numbers
  • Invalid inputs: Wrong type, out of range

📝 Test Case Builder

Plan your test cases (saves automatically):

MIN INPUT
TYPICAL INPUT
MAX INPUT
EXPECTED @ MIN
EXPECTED @ TYPICAL
EXPECTED @ MAX
✅ Test cases saved to browser!

⚠️ Common Misconceptions

  • Syntax error = logic error: No! Syntax errors prevent running. Logic errors let it run but give wrong results.
  • "It runs, so it's correct": A program can run without crashing but still have logic errors.
  • "I tested it once": One test case isn't enough. You need multiple cases including boundaries.
  • Overflow only happens with big numbers: It depends on the data type's range, not just "big" numbers.

📝 Exam Tip

AP CSP questions often show code with errors and ask you to identify the type OR identify which test case would reveal the bug. Practice distinguishing between error types—especially logic vs syntax and runtime vs overflow.

📝 Practice Quiz

Question 1 of 7
A program compiles and runs but displays "Welcome" when it should display "Goodbye". This is a:
B) The program runs but produces wrong output—classic logic error. The algorithm is flawed.
Question 2 of 7
Which error prevents a program from running at all?
A) Syntax errors violate language rules and prevent the program from starting. Other errors occur during or after execution begins.
Question 3 of 7
An 8-bit unsigned integer can store 0-255. What happens if you try to store 256?
D) 256 exceeds the maximum value (255), causing an overflow error. The value may wrap to 0 or cause unexpected behavior.
Question 4 of 7
Which debugging technique involves stepping through code line by line with sample inputs on paper?
C) Hand tracing means manually tracking variable values on paper as you step through each line of code.
Question 5 of 7
For a function that accepts ages 0-120, which are appropriate boundary test values?
B) Test at and just beyond boundaries: -1 (below min), 0 (min), 120 (max), 121 (above max).
Question 6 of 7
A program crashes when dividing by a user-entered value of zero. This is a:
C) Division by zero causes a crash during execution—a runtime error. The syntax is valid, but the operation fails at runtime.
Question 7 of 7
Why are program requirements needed to create test cases?
A) Requirements define expected behavior. Without them, you can't determine if outputs are correct or identify appropriate test inputs.
0/7

❓ Frequently Asked Questions

What's the difference between syntax and logic errors?+

Syntax errors violate language rules and prevent running. Logic errors allow execution but produce wrong results because the algorithm is flawed.

What is an overflow error?+

An overflow occurs when a number exceeds the storage range for its data type. For example, storing 256 in an 8-bit unsigned integer (max 255) causes overflow.

What are boundary test cases?+

Boundary tests check values at minimum, maximum, and just beyond those limits. This catches off-by-one errors and edge cases that typical values might miss.

How does hand tracing help debugging?+

Hand tracing means stepping through code line by line with sample inputs, tracking variable values on paper. You can see exactly where actual behavior differs from expected.

Why can a program run but still be wrong?+

If the syntax is valid, the program runs. But logic errors mean the algorithm doesn't correctly solve the problem—it produces wrong outputs even though it doesn't crash.

What test cases should I create?+

Create tests for: typical inputs, boundary values, just beyond boundaries, edge cases (empty, zero), and invalid inputs. Base expected outputs on program requirements.

📚 About This Guide

This AP CSP Topic 1.4 study guide is developed by NUM8ERS Institute & Education LLC Dubai, specializing in AP and IB exam preparation.

Official references:

More resources: