Learn › Class 12 › Computer Science / Informatics Practices › Python revision, functions, exceptions
Exception handling
Remember
- Syntax errors stop a program before it runs; exceptions happen while it runs.
- try → except (on error) → else (no error) → finally (always).
- Use raise to signal an error and assert to check a condition.
Quick self-check
Why put specific except blocks before a general except?
Check
Python uses the first matching block, so a general one first would hide the specific ones.
Which exception does d['x'] raise if the key is missing?
Check
KeyError.