Published by Patrick Mutisya · 14 days ago
Locate and identify the different types of errors that can occur in a program and understand how they are detected during testing and maintenance.
Errors are generally grouped into three broad categories, each with sub‑types that are important for programmers to recognise.
| Error Type | Description | Typical Detection Stage | Example |
|---|---|---|---|
| Syntax Error | Incorrect use of language constructs; the compiler cannot translate the source code. | Compilation | Missing semicolon: int x = 5 instead of int x = 5; |
| Type Mismatch | Assigning a value of one data type to a variable of an incompatible type. | Compilation | Assigning a String to an int variable. |
| Undeclared Identifier | Using a variable or function name that has not been declared. | Compilation | Calling calculateTotal() without a prior definition. |
| Division by Zero | Attempting to divide an integer or floating‑point number by zero. | Runtime (exception) | int result = a / b; // b = 0 |
| Null Reference | Dereferencing a variable that holds no object reference. | Runtime (exception) | String s = null; int len = s.length(); |
| Array Index Out of Bounds | Accessing 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 Error | Algorithmic 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 Error | Loop 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 Leak | Failure to release system resources such as files or memory. | Testing (system) and Maintenance | Opening a file with FileReader but never calling close(). |
| Concurrency Error | Incorrect handling of shared data in multi‑threaded programs (e.g., race conditions). | Testing (stress) and Maintenance | Two threads incrementing the same counter without synchronization. |
Once errors are identified, they are addressed through the following maintenance types: