Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Supplementary programming practice/Defensive Design

Anticipate misuse

301.16 Defensive Design

Practise exam questions

Defensive Design — Note 1 of 5

Predict invalid input.

What you need to know

Defensive design means writing code that handles unexpected or invalid input gracefully instead of crashing (e.g. wrapping int(input(...)) in try/except). Always assume the user will make mistakes.

What to know

  • Users may enter text when numbers are expected
  • Users may leave fields blank
  • Users may enter values outside the valid range
  • Plan for every possible wrong input

Code examples

Anticipating misuse
python
# Without defence — crashes on bad input
age = int(input("Age: "))  # Crashes if user types "abc"

# With defence
try:
    age = int(input("Age: "))
except ValueError:
    print("Please enter a number")
← Previous topicClosing files301.15 File Handling TechniquesNext note →Validation checks301.16 Defensive Design

Back to Defensive Design

Specification notes for programming are in Paper 2.

Defensive Design

Note 1 of 5

  1. 1Anticipate misuse
  2. 2Validation checks
  3. 3Authentication
  4. 4Validation subprograms
  5. 5Error messaging
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Privacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).