Types of Errors

Computer Science: OCR GCSE, topic 2.3.8

Types of Errors

Syntax errors

Syntax errors

  • A syntax error is a mistake in the way the code is written.
  • It is similar to a spelling or grammar mistake in English.
  • Syntax errors prevent programs from running as a translator needs 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.
  • Programs will run, but their outcome will not be as intended.
  • They are much more difficult to debug than syntax errors.
  • Logic errors are hard to detect because the translator will not detect them 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.
  • These 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 errors 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?

  • You translate a program and see this error:

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

    Is this a logic error?

Practise this topic for free