Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Defensive Design

Error messaging

All topicsPractise exam questions
Knowledge organiser

Defensive Design

301.16e

Friendly feedback to users.

What you need to know

Good error messages tell the user what went wrong and how to fix it. They should be clear, polite, and specific — never show raw Python tracebacks to users.

Key points

  • Tell the user WHAT went wrong
  • Tell the user HOW to fix it
  • Be specific: "Enter a number between 1 and 10" not "Invalid"
  • Never show raw tracebacks to end users

Code examples

Friendly error messages
python
mark = input("Enter mark: ")
if not mark.isdigit():
    print("Please enter a whole number.")
elif int(mark) < 0 or int(mark) > 100:
    print("Mark must be between 0 and 100.")
else:
    print("Mark recorded: " + mark)