Types of Errors (2.6.a)
There are three main types of errors which will be found in programs:
- Syntax errors are where an error relates to the specific "grammar" of a programming language. For example, name = Perseverance Jeyacheya would raise a syntax error in python, because the string (Perseverance Jeyacheya) should be surrounded by quotes. The interpreter (or compiler) will generally flag up any syntax errors when it processes them.
- Logical errors have valid syntax, but cause bugs in the program. Logical errors are found during black box testing. For example, the following football league program would have a bug where teams are drawing, as no points would be awarded (and one point should be awarded to each team):
if scores[a] > scores[b]: points[a] += 3 if scores[a] < scores[b]: points[b] += 3
- Runtime errors can only be found while the code is executing ("running"). Consider the formula (a+b)/(c-d). If c == d, then the program will crash, as it is dividing by zero. It may be rare that c is made equal to d (or d is made equal to c), therefore runtime errors can often be the hardest to debug.