Key Idea: A program's data lives in variables of a declared type, and things go wrong at run time whatever the code says. So handling failure is part of writing the program, not something added afterwards.
Paper 1
- Short definitions and a trace.
- State, identify, outline — precise terms.
Paper 2
- Write or correct Python for a scenario — your paper is the Python version, option B.
- Construct, determine, suggest.
Both
- Trace tables and justified choices earn method marks even when the final answer slips.
🏷️ Choosing a data type
| Data | Type | Why |
|---|---|---|
| A count of items | Integer | Whole, and used in arithmetic |
| A price | Decimal | Exact to the penny — floating point is not |
| A phone number | String | Never added; leading zeros matter |
| Paid or unpaid | Boolean | Two states — text invites 'Y', 'y' and 'true' as well |
Is this value ever used in arithmetic? If not, it is text however many digits it has. Concatenating '5' and '3' gives '53'; adding 5 and 3 gives 8.
Important: Floating point stores values in binary, and 0.1 has no exact binary form. Additions accumulate a tiny error, so a total ends at 9.999999 instead of 10.00 — and a comparison with 10.00 then fails.
🌐 Scope
Local beats global
- A local variable exists only inside its function — a wrong value has one place to come from
- A global can be changed anywhere, so two parts of the program interfere invisibly
- A constant is fixed at declaration; the compiler rejects any change to it
- Pass values in as parameters and return results — then each function can be tested alone
🐞 The three kinds of error
| Kind | When it appears | Why it matters |
|---|---|---|
| Syntax | Before anything runs | Harmless — it is reported and cannot be ignored |
| Run-time | On some inputs, perhaps rarely | Crashes; may survive testing |
| Logic | Never reported | The dangerous one — a wrong answer that is simply used |
🛡️ Exception handling
Doing it properly
- Code that might fail goes in a TRY block; failure jumps to CATCH and the program continues
- An empty catch is worse than no catch — it turns a visible failure into a silent corruption
- A catch should log the details, tell the user something actionable, and recover or stop cleanly
- Validate what you can predict; catch what you cannot, such as a file disappearing mid-read
- The log entry and the user's message have different audiences and should differ
📝 Exam-style questions
A booking form reads a date of birth typed by the user. Suggest how the program should handle input that is not a valid date, and explain why a TRY/CATCH block alone is not enough.
🔒 Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.
A program stores a total as a decimal. A colleague suggests changing it to a floating-point number to save memory. Explain why this is a poor decision.
🔒 Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.
✅ Quick check
Cover the answers.
Which error type is never reported? A logic error — the program runs to completion and gives a wrong answer.
Why is a phone number a string? It is never used in arithmetic, and leading zeros would be lost if stored as a number.
Why is an empty CATCH block dangerous? It converts a visible failure into silent corruption — the program continues with data it knows is wrong.
What is casting? Converting a value from one type to another — such as input text to an integer. It fails if the text is not numeric.
Why prefer a local variable? A wrong value has one place to come from; a global can be changed anywhere in the program.
Exam tips
- Ask whether the value is used in arithmetic — that decides the type in one step.
- Money is decimal, never floating point. Say why: binary cannot hold 0.1 exactly.
- Name all three error types and say which one is dangerous, and why.
- Validation prevents predictable faults; exception handling contains unpredictable ones.
- Never leave a catch block empty — say what should be logged and what the user should see.
- Check whether a question indexes strings from 0 or from 1 before extracting anything.