Types of Errors (Edexcel GCSE Computer Science)

Revision Note

James Woodhouse

Expertise

Computer Science

Syntax, Logic & Runtime Errors

  • Designing algorithms is a skill that must be developed and when designing algorithms, mistakes and issues will occur

  • 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

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

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

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

Identifying Logic Errors

  • Logic errors can be slightly challenging to locate compared to syntax errors

  • This is because the program will still run but will not produce the expected output that the programmer intended

  • The most obvious areas to check for logic errors are:

    • Logical operators (<, >, ==, !=)

    • Boolean operators (AND, OR, NOT)

  • To help demonstrate this skill, a snippet of program code is used

r883LnnA_screenshot-2024-02-28-at-09-51-14
  • In this example, the incorrect logical operator has been used, OR instead of AND

  • The result means the else clause in the if statement would never be caught

screenshot-2024-02-28-at-09-51-20
  • At first glance, entering normal test data such as 14, the program works as intended

  • Entering erroneous data or boundary test data which is outside of the range would result in the error

    • When entering the age of 21, it still outputs that the user is in secondary school

screenshot-2024-02-28-at-09-51-35
  • Changing the OR to AND corrects the logic error

screenshot-2024-02-28-at-09-51-48
screenshot-2024-02-28-at-09-52-00

Worked Example

Dan is writing a program for maths students. To make sure that there are no logic errors in the program, Dan uses a test plan.

Describe what is meant by a logic error. [2]

Answer

  • The error does not prevent the program from running

  • But it does not produce the expected output / it does not do what the programmer intended

  • A reasonable example

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ā¤ļø Save My Exams

the (exam) results speak for themselves:

Did this page help you?

James Woodhouse

Author: James Woodhouse

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.