Seneca

Types of Errors

Computer Science: OCR GCSE, topic 2.3.11

Types of Errors

Syntax errors break the rules of the programming language. A logic error makes a program produce the wrong result while still running. Runtime errors happen while a program is running.

Syntax errors

Syntax errors

  • A syntax error is a mistake in the way the code is written.
  • A syntax error is similar to a spelling or grammar mistake in English.
  • Syntax errors prevent programs from running.
  • A translator needs the code to be syntactically correct.
  • Syntax errors are some of the easier bugs to fix in a broken program.
Examples of syntax errors

Examples of syntax errors

  • prnt("Hello, world!");
  • Incorrect subroutine identifier.
  • newbalance = newBalance * 1.05;
  • Wrong capitalisation in variable identifier.
  • myBoolean = True NOT False;
  • NOT does not take two operands.
Logic errors

Logic errors

  • Logic errors are mistakes in the logic of the program.
  • A program with a logic error will run.
  • However, the program's outcome will not be as intended.
  • Logic errors are much more difficult to debug than syntax errors.
  • Logic errors are hard to detect.
  • A translator will not detect logic errors for us.
Examples of logic errors

Examples of logic errors

  • Many logic errors arise from the use of the wrong boolean operator, e.g. mixing up AND and OR.
  • Many logic errors arise from putting menu options the wrong way around in a selection statement.
Runtime errors

Runtime errors

  • Runtime errors are errors that happen while the program is running.
  • Runtime errors cannot be found during translation.
  • Runtime errors can only be detected while a program is running.
  • The chance of experiencing a runtime error can be reduced through testing.
  • Runtime errors are the trickiest of the three types of error because they are not always found during development.
  • Software users may first encounter runtime errors.
Examples of runtime errors

Examples of runtime errors

  • Bad inputs that throw an unhandled exception.
  • Receiving unexpected or corrupted data.
  • Running out of memory.

Test yourself on Types of Errors

  • Why do syntax errors prevent programs from running?

  • Which of the following are syntax errors?

  • Would the following code cause a syntax error?

    print("Hello, world!")

  • Why is it more difficult to detect a logic error than a syntax error?

  • A program is translated. The translator shows this error:

    ERROR LINE 13 "x = True NOT False" Incorrect use of operator

    Is this error a logic error?

Practise this topic for free