Module 30: Programming Project

Lesson 4 of 5 · 15–25 minutes

Error handling and testing the whole program

🏠The everyday picture

A shop's soft opening: invite friends, let them try to break things, fix what goes wrong, then open to the public.

📘What it really is

🖱️Try it

Write a test for each requirement that doesn't have one. Then try to break the program by hand: negative amounts, text instead of numbers, a deleted data file, a data file with broken JSON, selling more stock than exists. Fix each problem and add a test for it.

✅Quick check

What does "validate at the edges" mean?

Show the answer

Check all data from outside (input, files, APIs) once, as it enters; then inner code can rely on it.

Your data file contains broken JSON. What should happen?

Show the answer

A clear message, no crash, and no silent loss of data (for example, keep a backup of the broken file and start fresh only after telling the person).

← PreviousBuilding in small steps, with AI
ProLearners Assist