bare except
An except clause with no exception type, which catches every error, including typing mistakes and Control-C.
Swallowing every exception hides real bugs and can leave a program running in a broken state.
In more detail
It hides bugs: a NameError from a misspelt variable is silently swallowed. Catch the specific exceptions you expect, or at most except Exception, and never leave the handler empty without a reason.
Related terms
- try statement — The statement that runs a block of code and, if a listed exception happens there, runs an except block instead of letting the program stop.
- exception hierarchy — The family tree of exception classes, with BaseException at the top and Exception above nearly every error you will catch.
Taught in
- CGI: Dynamic Web Pages — Hands-on Python: Complete Video Course & Book
- Exceptions: try, except, else, finally — Hands-on Python: Complete Video Course & Book
- The Exception Family Tree — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Try, Except, Else And Finally — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions And Exceptions Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Twelve Traps, One Shape Each — 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
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep