Bird
0
0

Which of the following is the correct syntax to catch all exceptions except system-exiting ones?

easy📝 Syntax Q12 of 15
Python - Custom Exceptions
Which of the following is the correct syntax to catch all exceptions except system-exiting ones?
Aexcept SystemExit:
Bexcept BaseException:
Cexcept Exception:
Dexcept RuntimeError:
Step-by-Step Solution
Solution:
  1. Step 1: Recall exception hierarchy for catching exceptions

    Catching Exception catches most errors but excludes system-exiting exceptions like SystemExit and KeyboardInterrupt.
  2. Step 2: Identify correct syntax

    except Exception: is the standard way to catch all regular exceptions safely.
  3. Final Answer:

    except Exception: -> Option C
  4. Quick Check:

    Use Exception to catch all but system-exiting exceptions [OK]
Quick Trick: Use except Exception to avoid catching system-exit errors [OK]
Common Mistakes:
  • Using except BaseException catches system exit too
  • Catching only RuntimeError misses many exceptions
  • Using except SystemExit catches only exit exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes