Skip to main content
United StatesComputer Science PrinciplesSyllabus dot point

What kinds of errors do programs have, and how do programmers find and fix them?

Topic 1.4 Identifying and Correcting Errors: programs contain logic, syntax, runtime and overflow errors, and programmers find and fix them by testing with carefully chosen inputs and debugging.

A focused answer to AP CSP Topic 1.4, covering logic, syntax, runtime and overflow errors, testing with chosen inputs including edge cases, debugging strategies such as tracing and adding display statements, and how to describe testing in the Create task.

Generated by Claude Opus 4.810 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this topic is asking
  2. The four error types
  3. Testing with chosen inputs
  4. Debugging strategies
  5. Try this

What this topic is asking

The College Board (Topic 1.4) wants you to recognize the types of program errors and know how to find and fix them. Errors fall into categories (logic, syntax, runtime, overflow), and the way you find each differs. The key skill is testing: running the program with carefully chosen inputs, including edge cases, and comparing actual output to expected output. You then debug: locate the cause and correct it. The Create performance task asks you to describe your testing in terms of inputs and expected outputs.

The four error types

The trickiest to spot is the logic error, because nothing crashes: the program runs cleanly and confidently gives the wrong answer. Displaying a sum when you meant an average is a logic error.

Testing with chosen inputs

For a procedure that finds the largest value in a list, good test inputs include a typical list ([4, 9, 2], expect 9), a single-element list ([7], expect 7), and a list where the largest is first or last.

Debugging strategies

Once a test fails, you locate and fix the cause:

  • Trace the code by hand, following the value of each variable statement by statement.
  • Add DISPLAY statements to print intermediate values and see where the actual value diverges from the expected one.
  • Narrow the problem, isolating the smallest section of code that reproduces the wrong behavior.
  • Fix and retest to confirm the correction works and did not break anything else.

Try this

Q1. A program crashes when it tries to access the 10th element of a list that has only 8 elements. What type of error is this? [1 point]

  • Cue. A runtime error: the program crashes during execution because the index does not exist.

Q2. Why is it important to test a program with edge cases such as an empty list? [2 points]

  • Cue. A program can handle typical inputs correctly but fail at boundaries; edge cases reveal these failures so they can be fixed before users hit them.

Exam-style practice questions

Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

AP 2021 (style)1 marksMultiple choice. A program is supposed to display the average of two numbers but instead displays their sum. The program runs without crashing. What type of error is this? (A) A syntax error (B) A runtime error (C) A logic error (D) An overflow error
Show worked answer →

The answer is (C).

The program runs successfully but produces the wrong result (sum instead of average): that is a logic error, a mistake in the program's logic. (A) syntax errors stop the program from running at all because the code breaks the language rules. (B) runtime errors cause the program to crash while running (for example dividing by zero). (D) overflow errors occur when a value exceeds the range a variable can store. None of those match a program that runs but gives a wrong answer.

Markers reward distinguishing a logic error (runs, wrong output) from syntax and runtime errors.

AP 2023 (style)4 marksCreate performance task (style). Write two to three sentences describing how you tested one of the procedures in your program, naming the inputs you used and the output you expected for each.
Show worked answer →

A strong response names specific test inputs (including an edge case) and the expected output for each.

Model response: "I tested my procedure findMax, which returns the largest value in a list. I called it with the list [4, 9, 2], expecting 9, and with the single-element list [7], expecting 7 (an edge case). Both returned the expected value, so I was confident the procedure handled both typical and boundary inputs."

This earns credit because it (1) identifies the procedure and what it should do, (2) names specific inputs including an edge case (a one-element list), and (3) states the expected output for each. A response that says "I tested it and it worked" gives no inputs or expected outputs and would not score.

Related dot points

Sources & how we know this