Simple error handling techniques - CCEAProgram errors

In some ways, computer languages are no different to our own. They have strict rules programmers must follow in order to make their programs understood. Mistakes throw up errors, which must be fixed.

Part ofDigital Technology (CCEA)Digital development concepts (programming)

Program errors

There are three different types of error that can occur when we are writing programs – syntax errors, run time errors and logic errors.

Syntax error

Syntax is the spelling and grammar of programming language. A syntax error is when the sequence of characters or tokens intended to be written in a particular programming language is written incorrectly.

When you break these syntax rules for writing your program, this is often due to misspelling or the use of incorrect punctuation. A syntax error will cause the program not to run.

For example:

if isPlateValid(): print('Valid Reg#')
else: print(Invalid Reg #')

As print('Invalid Reg #') is missing a ' character, this will result in an error.

Run time error

A run time error will cause a computer or program to crash even if there is nothing wrong with the program code.

It is detected after or during the execution of a program, and is usually a result of insufficient memory, or instructions being written in the wrong order.

For example, a . This may be due to an infinite loop (e.g., a WHILE loop with no count control) and causes a program to continually use up more RAM (incorrectly managing memory) while the program is running.

Division by zero is another common run time error. This occurs when the program attempts to divide a number by zero.

Logic error

The program works, but produces different results from those you designed or expected. Logic errors are notoriously difficult to debug.

For example, if a programmer wanted to get the average of three numbers and produced the following code:

num1 = 7
num2 = 8
avg = (num1 + num2)/3

This will result in an error due to a flaw in the programmer's logic (dividing the total by 3 to get the average when there are only 2 numbers).