Find Mistake: Bare Except Clause
Find the Mistake Medium
Question
This code has a bad practice. What is wrong?
Code
try:
result = 10 / x
except:
print("Error")
Hint
Catching all exceptions indiscriminately is dangerous.
Explanation
A bare except: catches all exceptions, including KeyboardInterrupt and SystemExit, making it hard to interrupt the program or debug. The fix is to catch specific exceptions: except ZeroDivisionError: or at least except Exception:.
Related Resources
Related Lessons
- Exceptions
Exception handling best practices.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.