SOARDO
Software Engineer (SDE)pythonintermediate3 interactive MCQs in app

Custom Exception Classes

subclass Exception not BaseExceptionshared package base hierarchy & metadatachaining tracebacks with raise ... from err

Custom exceptions subclass `Exception` (NEVER `BaseException`, which catches `SystemExit`/`KeyboardInterrupt`) and carry domain-meaningful names (`InsufficientEvidenceError`, `RateLimitError`) and structured attributes (`status_code`, `retry_after`). Defining one package base exception lets callers catch all domain errors with `except DomainError:` while handling specific subclasses finely.

`class GradingError(Exception): ...` with `ProviderTimeoutError(GradingError)` raised via `raise ProviderTimeoutError(...) from exc` lets routes return 502 while preserving the root HTTP traceback!
catching generic `ValueError` everywhere loses distinction between validation bugs vs external rate limits, or forgetting `raise CustomError(...) from err` drops the original traceback cause.
Python Exceptions: An Introduction — Real Pythonread ↗Exercism Python Track (Interactive)practice ↗

Practice Custom Exception Classes with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides