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.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
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
DISPLAYstatements 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
- Topic 1.3 Program Design and Development: programs are developed iteratively through investigating, designing, prototyping and testing, using tools such as program requirements, specifications and feedback.
A focused answer to AP CSP Topic 1.3, covering the iterative development process, investigating and reflecting, program requirements and specifications, designing and prototyping, the role of user feedback, and how the Create task documents the development process.
- Topic 1.2 Program Function and Purpose: a program is a sequence of instructions that accomplishes a goal; programs receive input, produce output, and their behavior is shaped by purpose and intended users.
A focused answer to AP CSP Topic 1.2, covering what a program is, function versus purpose, the input-process-output model, event-driven programs, program behavior and intended users, and how the Create task asks you to describe your program's purpose and function.
- Topic 3.6/3.7 Conditionals and Nested Conditionals: conditional (IF/ELSE) statements select which code runs based on a Boolean condition, and nested conditionals handle multiple decision paths.
A focused answer to AP CSP Topics 3.6 and 3.7, covering IF and IF/ELSE selection, the role of the Boolean condition, nested conditionals for multiple paths, tracing which branch runs, and writing decision logic in AP CSP pseudocode.
- Topic 3.12-3.14 Procedures and Libraries: procedures are named, reusable blocks with parameters and return values, and libraries and APIs package procedures so programmers reuse code through abstraction.
A focused answer to AP CSP Topics 3.12 to 3.14, covering defining and calling procedures, parameters and return values, procedural abstraction, modularity, libraries and APIs, and how reusing procedures manages complexity, with worked pseudocode.
- Topic 2.1 Binary Numbers: computers represent all data with bits (binary digits); numbers, text, images and sound are encoded in binary, and fixed bit-widths cause overflow and rounding.
A focused answer to AP CSP Topic 2.1, covering bits and bytes, binary-to-decimal conversion, why all data is represented in binary, analog versus digital, fixed bit-width consequences (overflow and rounding errors), and abstraction in data representation.
Sources & how we know this
- AP Computer Science Principles Course and Exam Description — College Board (2025)