Faults & Errors (Cambridge (CIE) A Level 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
Infinite loops
Pseudocode |
---|
|
Logic errors
Line | Error | Correction |
---|---|---|
| The check allows one value to be negative, 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 runtime error is where an error causes a program to crash
Examples of runtime errors are:
Dividing a number by 0
Index out of the range of an array
Unable to read or write a drive
Pseudocode |
---|
|
Runtime error
Line | Error | Correction |
---|---|---|
| Only one parameter is passed instead of two – will crash at runtime | Should be |
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 |
You've read 0 of your 5 free revision notes this week
Unlock more, it's free!
Did this page help you?