Robust Programming
Revise Robust Programming for GCSE Computer Science with this free worksheet and full mark scheme — Foundation and Higher exam-style questions with worked answers. A robust program anticipates unexpected input and keeps working sensibly instead of failing.
Free downloads
These worksheets and mark schemes are original, written for Virtus Academy and checked against the current AQA specification. Every worksheet comes with a full mark scheme.
Topic overview
Robust programming means writing code that continues to work sensibly when things go wrong, rather than crashing.
Anticipating misuse is the core idea. A program asking for a number must cope with the user entering text. A program dividing by a user-supplied value must cope with zero. A program reading a file must cope with the file being missing.
Three techniques are used. Validation checks input before it is used. Authentication restricts who can access the program. Maintainability measures — meaningful names, comments, indentation and subroutines — make the code easier to correct when a problem is found. A robust program handles the unexpected gracefully with a helpful message rather than failing.
Revision notes
Anticipating misuse
Assume users will enter unexpected input, whether by mistake or deliberately.
A number field must cope with text. A divisor must cope with zero. A file operation must cope with the file being absent. Each of these would crash an unprotected program.
The techniques
Validation: check input is sensible before using it.
Authentication: restrict access to authorised users. Maintainability: meaningful names, comments, indentation and subroutines, so problems can be found and fixed quickly.
Handling errors gracefully
A robust program displays a helpful message and allows the user to try again.
Crashing loses any unsaved work and tells the user nothing useful. Recovering sensibly is the difference between a robust program and a fragile one.
Key points
- Robust programs cope when things go wrong.
- Anticipate users entering unexpected input.
- Validation checks input before use.
- Authentication restricts access.
- Maintainability helps problems be fixed quickly.
- Errors should give a helpful message, not a crash.
Worked examples
Example 1
A program asks the user for a number. State one thing a robust program should handle. [2 marks]
Working
Example 2
Name three techniques used to make a program robust. [3 marks]
Working
Example 3
Explain why a program should display a message rather than crashing when an error occurs. [2 marks]
Working
Common mistakes
Assuming users will enter valid data.
Robust programs assume the opposite.
Naming only validation.
Authentication and maintainability are also required.
Confusing robustness with speed.
Robustness is about coping with the unexpected.
Saying a robust program never has errors.
It handles them gracefully rather than avoiding them entirely.
Exam tips
- Give a specific example of misuse to anticipate.
- Name all three techniques when asked.
- Describe graceful handling, not just error prevention.
- Link maintainability to fixing problems quickly.
Key terms
- Robust
- Continuing to work sensibly when things go wrong.
- Validation
- Checking input is sensible before use.
- Maintainability
- How easily code can be understood and corrected.
- Graceful
- Handling an error with a helpful message rather than crashing.
Related topics
Written and reviewed against the current AQA specification. Spotted an error? Let us know.