Home > Software Design and Development > Core > Software Development Cycle > Detecting and correcting errors
This material differentiates between the types of errors encountered during the testing phase, lists some common causes of each type of error and provides practise in detecting and correcting errors.
H4.2 A student applies appropriate development methods to solve software problems.
H4.3 A student applies a modular approach to implement well structured software solutions and evaluates their effectiveness.
Students learn to differentiate between the types of errors encountered during the testing phase and to recognise the cause of a specific error and determine how to correct it (SDD Syllabus, p.43).
The following headings may help you navigate:
Syntax errors are written statements that do not conform to the rules of the language. The rules of the language are shown in metalanguages (BNF, EBNF or railroad diagrams) that describe the language.
Most modern programming environments have syntax prompts and auto-code completion features which help reduce the number of syntax errors made. Built-in debuggers assist in tracing code and locating errors.
Syntax errors can be caused by:
There are five syntax errors in the Visual Basic code below. See how many you can find.

For the following sections of PHP code find and fix the Syntax errors:
| CODE | Error | Fixed code |
|---|---|---|
| Echo “Hello there”; | Spelling of function | Echo “Hello there”; |
| IF ($age < 13){ Echo “Child” } |
1 error | |
| IFS (age < 13){ Echo “Child”; } |
2 errors | |
| $count = 0; WHILE count < 10 $count = $count + 1; Echo “$count “; } |
2 errors |
Logic errors have occurred when incorrect algorithms result in unexpected output. Logic errors should be detected by desk checking the algorithm with carefully chosen test data. Peer checking by a colleague is another way to locate logic errors.
Trace the Visual Basic source code below to find the logic error.
Private Sub cmdPrintSequence_Click()
Dim number As Integer
number= 11
Do
picSequence.Print number
number = number - 3
Loop Until number = 0
End Sub
For the following lines of PHP determine the output of the code and explain and fix the logic errors:
| Code | Output | Explain and fix the error |
|---|---|---|
| $count = 0; WHILE ($count < 3) { $count = $count + 1; Echo “ $count”; } |
||
| $count = 0; WHILE ($count < 5) { Echo “ $count; } |
||
| $index = 0; WHILE ($index < 5) { $count = $count + 1; Echo “ $count”; } |
||
| $count = 0; WHILE ($count < 5) { Echo “ $count } |
||
| $count = 0; WHILE ($count < 5) { $count = $count - 1; Echo “ $count”; } |
| Code | Output | Explain and fix the error |
|---|---|---|
| $average = $num1 + $num2 / 2; Echo “The average is”; $average”; |
| Test Data | Output |
|---|---|
| 14 | Not legal |
| 25 | Legal |
| 18 | Legal |
| Code | Explain and fix the error |
|---|---|
| IF ($age > 18) { Echo “Legal”; }ELSE{ Echo “Not legal”; } |
Logic errors can be difficult to locate and fix. Careful hand checking of the original algorithm with carefully chosen test data is generally the most efficient way to find logic errors.
Most programming environments have a debugger which allows the setting of breakpoints, watch expressions to observe variables or single line step routines.
Programmers can also add temporary output statements to observe what is happening.
Well-modularised code is easier to debug for logic errors.
Here is another example of Visual Basic code containing a logic error. Can you debug it? How might this error be fixed?
Private Sub cmdSum_Click()
Dim number As Integer
Dim sum As Integer
number = Val(InputBox("Enter the integer number to be summed", number))
sum = 0
Do
number = number – 1
sum = sum + number
Loop Until number = 0
picDisplay Print "The sum of all integers between 0 and your number = " & sum
End Sub
Run-time errors cause a program to fail or crash after it has been compiled and executed. Run-time errors can be very difficult to locate. Run-time errors are located by running the program with a well-chosen range of test data. Beta version testing involves independent operators who try to find as many execution errors as possible.
Causes of run-time errors
Common causes of run-time errors include:
Correcting run-time errors
Run-time errors can be very difficult to locate so all programs need thorough testing. Many run-time errors can be avoided using error-handling routines.
In Visual Basic 6.0, for example
on Error GoTo ErrorHandler
[Your code here]
Exit Sub Prevents ErrorHandler executing if no error
ErrorHandler:
[error-handling routine - including a message]
Resume Re-executes code that caused the error
(Resume Next jumps to the line following the error)
End Sub
Explain and fix the run-time error of the following PHP code
| Code | Output | Explain and fix the error |
|---|---|---|
| $count = 0; WHILE ($count < 5) { Echo “ $count”; } |