Faults & errors (Cambridge (CIE) AS Computer Science): Revision Note
Exam code: 9618
Error types
What are the common types of error?
Designing algorithms is a skill that must be developed and when designing algorithms, mistakes and issues will occur
Trace tables can also help to find any kind of error in a program or algorithm
There are three main categories of errors that when designing algorithms a programmer must be able to identify & fix, they are:
Syntax errors
Logic errors
Runtime errors
Syntax errors
What is a syntax error?
A syntax error is an error that breaks the grammatical rules of a programming language and stops it from running
Examples of syntax errors are:
Typos and spelling errors
Missing or extra brackets or quotes
Misplaced or missing semicolons
Invalid variable or function names
Incorrect use of operators
Incorrectly nested loops & blocks of code
Pseudocode - with syntax errors |
|---|
|
Pseudocode - without syntax errors |
|
Syntax errors |
|
Logic errors
What is a logic error?
A logic error is where incorrect code is used that causes the program to run, but produces an incorrect output or result
Logic errors can be difficult to identify by the person who wrote the program, so one method of finding them is to use 'Trace Tables'
Examples of logic errors are:
Incorrect use of operators (< and >)
Logical operator confusion (AND for OR)
Looping one extra time
Indexing arrays incorrectly (arrays indexing starts from 0)
Using variables before they are assigned
Using an array index that is one too high or one too low
Pseudocode |
|---|
|
Logic errors
Line | Error | Correction |
|---|---|---|
| The check allows one value to be negative or zero, which is not valid | Should be |
| Incorrect calculation: subtracts instead of multiplying to find the area | Should be |
Runtime errors
What is a runtime error?
A run-time error is an error that occurs while the program is running and causes it to crash or stop responding ('freeze')
Examples of run-time errors are:
Dividing a number by 0
Using an array index outside the bounds of the array
Calling a function with invalid parameters
A conditional loop whose terminating condition is never satisfied, so the program stops responding
Being unable to read or write a file
Pseudocode |
|---|
|
Runtime error
Line | Error | Correction |
|---|---|---|
| If the user enters 0 for the number of students, the program tries to divide by zero and crashes while it is running | Check the value before dividing:
|
Worked Example
Each pseudocode statement in the following table may contain an error due to the incorrect use of the function or operator.
Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error.
You can assume that none of the variables referenced are of an incorrect type.[5]
Statement | Error |
|---|---|
| |
| |
| |
| |
|
Answer
Statement | Error |
|---|---|
| Should be arithmetic operator (not &) OR 2 and 4 should be CHAR / STRING |
| NO ERROR |
| Not Boolean values / incorrect operator OR Condition incorrect |
|
to a Boolean value / incorrect operator |
| Can’t add string to number / "Done" is not a number |
Unlock more, it's free!
Was this revision note helpful?
Build on this topic