You’ll be able to
- Catch specific exceptions with
try/exceptblocks - Raise your own exceptions with
raise - Use
finallyfor cleanup that must always run - Read Python tracebacks to diagnose bugs faster
Loading lesson…
Why this matters
Bare except: clauses hide KeyboardInterrupt and SystemExit — a classic reason CI jobs won't die on Ctrl-C. Sentry, structlog, and every FastAPI exception handler depend on precise exception hierarchies and raise ... from err chaining.
Common pitfalls
except Exception:swallowing errors without logging — always log or re-raise; silent failures rot codebases.- Losing traceback context by re-raising as
raise NewError(str(e))— useraise NewError(...) from einstead. - Putting cleanup in
exceptinstead offinally— cleanup won't run on the happy path.