exception hierarchy
The family tree of exception classes, with BaseException at the top and Exception above nearly every error you will catch.
In more detail
An except clause catches the named class and all its subclasses, so except Exception catches ValueError and KeyError but not KeyboardInterrupt or SystemExit, which inherit from BaseException directly. Your own exceptions should inherit from Exception.
Related terms
- exception — An error object a program raises to stop normal flow and report that something went wrong.
- custom exception — An exception class you define yourself, usually in two lines by subclassing Exception, to name an error specific to your program.
- inheritance — Declaring one class or type as a specialised version of another, so it receives the parent's members and can be used wherever the parent is expected.
Taught in
- Multiple Parameters — Hands-on Python: Complete Video Course & Book
- Local Scope And Global Constants — Hands-on Python: Complete Video Course & Book
- Any Type As A Condition — Hands-on Python: Complete Video Course & Book
- Exceptions: try, except, else, finally — Hands-on Python: Complete Video Course & Book
- Raising, And Writing Your Own Exception — Hands-on Python: Complete Video Course & Book
- Reading A Traceback Like A Professional — Hands-on Python: Complete Video Course & Book
- The Exception Family Tree — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Parameters, Arguments And Scope — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Handlers, args, raise And assert — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Classes, Objects And Two Stacks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep