Bird
0
0

Why should you avoid catching BaseException directly in most cases?

hard📝 Conceptual Q10 of 15
Python - Custom Exceptions
Why should you avoid catching BaseException directly in most cases?
AIt does not catch any exceptions
BIt catches system-exiting exceptions like KeyboardInterrupt, preventing program exit
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 like KeyboardInterrupt and SystemExit.
  2. Step 2: Consequence of catching BaseException

    Catching BaseException prevents system-exiting exceptions from terminating the program, which can cause unwanted behavior.
  3. Final Answer:

    It catches system-exiting exceptions like KeyboardInterrupt, preventing program exit -> Option B
  4. Quick Check:

    Avoid catching BaseException to allow normal program exit [OK]
Quick Trick: Avoid catching BaseException to not block program exit [OK]
Common Mistakes:
  • Thinking BaseException only catches syntax errors
  • Believing it causes syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes