Bird
0
0

Why should you avoid catching BaseException directly in Python?

hard📝 Conceptual Q10 of 15
Python - Exception Handling Fundamentals
Why should you avoid catching BaseException directly in Python?
AIt catches system-exiting exceptions like KeyboardInterrupt and SystemExit
BIt does not catch any exceptions
CIt only catches syntax errors
DIt causes syntax errors
Step-by-Step Solution
Solution:
  1. Step 1: Understand BaseException role

    BaseException is the root of all exceptions including system-exiting ones.
  2. Step 2: Identify why catching BaseException is discouraged

    Catching BaseException also catches KeyboardInterrupt and SystemExit, which should usually be allowed to exit.
  3. Final Answer:

    It catches system-exiting exceptions like KeyboardInterrupt and SystemExit -> Option A
  4. Quick Check:

    Avoid catching BaseException to not block system exit [OK]
Quick Trick: BaseException includes system exit exceptions, avoid catching it [OK]
Common Mistakes:
  • Thinking BaseException catches no exceptions
  • Confusing with syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes