RisingCoder Full course โ†’
Day 1Day 2Day 3Day 4
๐Ÿš‘
STUDENT NOTES ยท DAY 14 OF 24

Error Shields ๐Ÿ›ก๏ธ

Users type "ten" instead of 10. WiFi dies. Files go missing. Today your programs learn to survive it all.

1Watch a program die ๐Ÿ’€

๐Ÿž
Bugly: My favourite moment โ€” the user types words where numbers belong:

2The shield: try / except

๐Ÿ
Py: try = attempt this. except = if it explodes, do THIS instead of crashing. The program lives on!

3Different shields for different errors

๐Ÿฆ‰
Professor Hoot: Catch specific errors so each mistake gets the right message. A good program is a good doctor โ€” right diagnosis, right cure.

4finally โ€” the loyal cleanup crew

๐Ÿค–
Bittu: finally runs NO MATTER WHAT โ€” error or no error. Perfect for cleanup jobs like closing things.

5Quick quiz! ๐Ÿง 

What error does int("hello") raise?
๐Ÿ’ก Right type (a string), impossible VALUE โ€” no number hides inside "hello".
When does the finally block run?
๐Ÿ’ก finally is the loyal friend: it shows up no matter how the try ended.

6Your mission ๐Ÿš€

Mission 1: Ask for the user's age with int(input()). Catch ValueError and reply "Numbers only, boss! ๐Ÿ˜„".
Mission 2: Build a divider: ask two numbers, divide, and catch ZeroDivisionError with a funny message.
Mission 3: Wrap yesterday's file-reading in try/except FileNotFoundError.

Day 14 done โ€” crash-proof coder! ๐Ÿ›ก๏ธ

Next: APIs โ€” your code talks to the internet.

Go to Day 15: APIs โ†’

๐ŸŽฎ Or test yourself in the Python Arcade โ†’