Locate and identify the different types of errors

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – 12.3 Program Testing and Maintenance

12.3 Program Testing and Maintenance

Objective

Locate and identify the different types of errors that can occur in a program and understand how they are detected during testing and maintenance.

Classification of Errors

Errors are generally grouped into three broad categories, each with sub‑types that are important for programmers to recognise.

  • Syntax (Compile‑time) Errors – violations of the language grammar.
  • Runtime Errors – problems that cause abnormal termination while the program is executing.
  • Logical (Semantic) Errors – the program runs without crashing but produces incorrect results.

Detailed Error Types

Error TypeDescriptionTypical Detection StageExample
Syntax ErrorIncorrect use of language constructs; the compiler cannot translate the source code.CompilationMissing semicolon: int x = 5 instead of int x = 5;
Type MismatchAssigning a value of one data type to a variable of an incompatible type.CompilationAssigning a String to an int variable.
Undeclared IdentifierUsing a variable or function name that has not been declared.CompilationCalling calculateTotal() without a prior definition.
Division by ZeroAttempting to divide an integer or floating‑point number by zero.Runtime (exception)int result = a / b; // b = 0
Null ReferenceDereferencing a variable that holds no object reference.Runtime (exception)String s = null; int len = s.length();
Array Index Out of BoundsAccessing an array element with an index outside its declared range.Runtime (exception)int[] a = new int[5]; a[5] = 10; // valid indices 0‑4
Logical ErrorAlgorithmic mistake that yields wrong output despite successful compilation and execution.Testing (system/integration)Using if (score > 50) instead of if (score >= 50) when the passing mark is 50.
Off‑by‑One ErrorLoop iterates one time too many or too few.Testing (unit)For for (i = 0; i <= n; i++) when the intention was to process exactly n items.
Resource LeakFailure to release system resources such as files or memory.Testing (system) and MaintenanceOpening a file with FileReader but never calling close().
Concurrency ErrorIncorrect handling of shared data in multi‑threaded programs (e.g., race conditions).Testing (stress) and MaintenanceTwo threads incrementing the same counter without synchronization.

How Errors Are Detected

  1. Compilation – Syntax, type, and declaration errors are reported by the compiler.
  2. Static Analysis – Tools examine source code without execution to find potential runtime problems (e.g., unused variables, possible null dereferences).
  3. Unit Testing – Individual components are tested in isolation; logical errors and off‑by‑one mistakes are often uncovered.
  4. Integration Testing – Interactions between modules are exercised; interface mismatches and resource leaks become apparent.
  5. System/Acceptance Testing – The complete system is run under realistic conditions; concurrency issues and performance‑related errors may surface.
  6. Runtime Monitoring – Logging, assertions, and exception handling help locate errors that only appear during execution.

Link to Maintenance Activities

Once errors are identified, they are addressed through the following maintenance types:

  • Corrective Maintenance – Fixes bugs and errors discovered after deployment.
  • Adaptive Maintenance – Modifies the program to work in a changed environment (e.g., new OS version).
  • Perfective Maintenance – Improves performance or adds minor enhancements.
  • Preventive Maintenance – Refactors code to reduce future error likelihood.

Suggested diagram: Flowchart showing the testing lifecycle (unit → integration → system → acceptance) and where each error type is most likely to be detected.