Types of Errors (Edexcel GCSE Computer Science): Revision Note

Exam code: 1CP2

James Woodhouse

Written by: James Woodhouse

Reviewed by: Lucy Kirkham

Updated on

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 5 free revision notes this week

Unlock more, it's free!

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

Expertise: Computer Science & English Subject Lead

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.

Lucy Kirkham

Reviewer: Lucy Kirkham

Expertise: Head of STEM

Lucy has been a passionate Maths teacher for over 12 years, teaching maths across the UK and abroad helping to engage, interest and develop confidence in the subject at all levels.Working as a Head of Department and then Director of Maths, Lucy has advised schools and academy trusts in both Scotland and the East Midlands, where her role was to support and coach teachers to improve Maths teaching for all.