Error Types (SQA National 5 Computing Science): Revision Note

Exam code: X816 75

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

What are errors?

  • When writing programs, mistakes can occur that stop them working correctly

  • You must be able to describe, identify, and exemplify the three main types of error:

    • Syntax errors

    • Logic errors

    • Execution (runtime) errors

  • You also need to explain the effect each one has on the program

Syntax errors

What is a syntax error?

  • A syntax error breaks the rules of the programming language and prevents the program from running

  • Examples include:

    • Missing brackets, colons, or quotation marks

    • Spelling mistakes in variable names

    • Incorrect indentation

    • Using an operator or keyword incorrectly

Examples

SQA Pseudocode

With syntax errors

RECEIVE name FROM (STRING) KEYBOARD
IF name = "Alice"        # missing THEN → prevents program from running
    SEND "Welcome Alice" TO DISPLAY
END IF

Corrected version

RECEIVE name FROM (STRING) KEYBOARD
IF name = "Alice" THEN
    SEND "Welcome Alice" TO DISPLAY
END IF

Python

With syntax errors

# Syntax error: missing colon and wrong variable name
name = input("Enter your name")
if name == "Alice"
    print("Welcome Alis")

Corrected version

name = input("Enter your name: ")
if name == "Alice":
    print("Welcome Alice")

Examiner Tips and Tricks

Use the phrase “prevents the program from running” when describing syntax errors.

Logic errors

What is a logic error?

  • A logic error occurs when the program runs but gives the wrong output because the logic is incorrect

  • Examples include:

    • Using < instead of <=

    • Adding instead of subtracting

    • Wrong formula or variable

    • Condition written incorrectly

Examples

  • A program is written to display You passed! if a student achieves a score of 50 or more

  • It should display You failed! is they achieve a score less than 50

SQA Pseudocode

With logic error - If the pass mark is meant to include 50, this will give the wrong result

RECEIVE score FROM (INTEGER) KEYBOARD
IF score > 50 THEN
    SEND "You passed!" TO DISPLAY
ELSE
    SEND "You failed!" TO DISPLAY
END IF

Corrected version

IF score >= 50 THEN
    SEND "You passed!" TO DISPLAY
ELSE
    SEND "You failed!" TO DISPLAY
END IF

Python

With logic error

score = int(input("Enter your score: "))

if score > 50:
    print("You passed!")
else:
    print("You failed!")

Corrected version

if score >= 50:
    print("You passed!")
else:
    print("You failed!")

Examiner Tips and Tricks

  • Use the phrase “produces an incorrect output” when describing logic errors

  • Trace tables can help you find logic errors step by step

Execution (runtime) errors

What is an execution (runtime) error?

  • An execution (runtime) error happens while the program is running and causes it to crash

  • Examples include:

    • Dividing by zero

    • Using a variable before it is assigned

    • Accessing an element outside the range of an array

    • Entering the wrong data type

SQA Pseudocode

With execution error - If the user enters 0 for num2, the program crashes.

RECEIVE num1 FROM (INTEGER) KEYBOARD
RECEIVE num2 FROM (INTEGER) KEYBOARD
SET answer ← num1 / num2
SEND "Answer: " & answer TO DISPLAY
# Program crashes if num2 = 0

Corrected version - with input validation

RECEIVE num1 FROM (INTEGER) KEYBOARD
RECEIVE num2 FROM (INTEGER) KEYBOARD

IF num2 = 0 THEN
    SEND "Error – cannot divide by zero" TO DISPLAY
ELSE
    SET answer ← num1 / num2
    SEND "Answer: " & answer TO DISPLAY
END IF

Python

With execution error

# Runtime error: divide by zero
num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))

answer = num1 / num2
print("Answer:", answer)

Corrected version - with input validation

num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))

if num2 == 0:
    print("Error – cannot divide by zero")
else:
    answer = num1 / num2
    print("Answer:", answer)

Examiner Tips and Tricks

Use the phrase “causes the program to crash” when describing runtime (execution) errors

Summary table

Error type

Description

Example cause

Effect on program

Exam phrase

Syntax

Breaks programming rules

Missing THEN or brackets

Program won’t run

Prevents the program from running

Logic

Incorrect algorithm

Wrong condition or operator

Wrong output

Produces an incorrect output

Execution (runtime)

Error during execution

Divide by zero, index error

Program crashes

Causes the program to crash

How to find and fix errors

  • Use trace tables or dry runs to follow program flow

  • Test with normal, extreme, and exceptional data

  • Read error messages carefully in your IDE

Worked Example

A program is designed to implement input validation, ensuring a numerical score entered by a user is within the acceptable range of 50 to 100, inclusive. If the score is invalid, the user should be prompted to re-enter the input until the condition is met.

The programmer writes the following pseudocode:

Line 1: RECEIVE score FROM KEYBOARD
Line 2: WHILE score < 50 AND score > 100 DO
Line 3:    SEND "Error: Score must be between 50 and 100." TO DISPLAY
Line 4:    RECEIVE score FROM KEYBOARD
Line 5: END WHILE

A user executes the program and inputs the score 10 at Line 1. The program immediately continues past Line 5, accepting the invalid input, and therefore does not function as intended.

(i) State the specific type of error present in the conditional statement at Line 2.

[1]

(ii) Explain why this error occurs, referencing the logical operator used.

[2]

(iii) Rewrite the condition at Line 2 to ensure the input validation works correctly.

[1]

Answers

(i)

  • The error is a logic error [1 mark]

(ii)

  • The logical operator AND is used where OR is required [1 mark]

  • A score can never be simultaneously less than 50 AND greater than 100 [1 mark]

    • Therefore, the condition score < 50 AND score > 100 is always False, meaning the conditional WHILE loop never executes, even when invalid exceptional data (like 10) is entered

(iii)

  • WHILE score < 50 OR score > 100 DO [1 mark]

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: 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.