Published by Patrick Mutisya · 14 days ago
In this section we examine how to locate, analyse and correct errors that have been identified during testing or in later maintenance phases. The process combines systematic testing techniques with disciplined debugging and documentation.
| Error Type | Typical Cause | Common Symptoms | Corrective Action |
|---|---|---|---|
| Syntax Error | Incorrect use of language grammar (missing semicolon, mismatched brackets) | Compiler/Interpreter stops with an error message | Refer to the error message, correct the offending line, re‑compile |
| Logical Error | Faulty algorithm or incorrect condition | Program runs but produces wrong output | Trace the algorithm, use print‑debugging or a debugger to inspect variable values, adjust logic |
| Runtime Error | Invalid operation during execution (division by zero, null reference) | Program aborts or throws an exception | Validate inputs, add exception handling, ensure resources are correctly allocated |
| Interface Error | Mismatch between modules or external systems | Incorrect data exchange, crashes at module boundaries | Check API contracts, data formats, and version compatibility |
| Performance Error | Inefficient algorithm or resource leakage | Slow response, high memory/CPU usage | Profile the program, replace with more efficient algorithm, optimise data structures |
print statements if a debugger is unavailable.Maintenance is divided into three recognised phases. Each phase has its own emphasis on error correction.
| Phase | Purpose | Typical Errors Addressed | Key Activities |
|---|---|---|---|
| Corrective Maintenance | Fix faults that cause the program to deviate from its specifications. | All error types identified after deployment. | Bug tracking, root‑cause analysis, patch development, regression testing. |
| Adaptive Maintenance | Modify the system to work in a changed environment (new OS, hardware, regulations). | Interface errors, configuration mismatches. | Impact analysis, code refactoring, compatibility testing. |
| Perfective Maintenance | Improve performance, readability, or add minor enhancements. | Performance errors, code‑smell, usability issues. | Profiling, code optimisation, documentation updates. |
Consider the following fragment intended to compute the factorial of a positive integer n:
int factorial(int n) {
int result = 1;
for (int i = 1; i < n; i++) {
result *= i;
}
return result;
}
The program returns result = (n‑1)! instead of n!. The error lies in the loop condition.
i < n, so it stops before multiplying by n.int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; i++) { // changed condition
result *= i;
}
return result;
}
n = 1, 5, 7. Expected results are \$1\$, \$120\$, \$5040\$ respectively.