LearnFrenzy
Sign in Take a free test

Exception Handling · Exception Handling MCQ · Question 3

Which except clause runs? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

A KeyError is raised. The clauses are except LookupError and then except KeyError. Which runs?

  • A except KeyError – the most specific wins
  • B Both
  • C Neither
  • D except LookupError – the first matching clause wins Correct
Correct Answer: Option D

KeyError is a subclass of LookupError, so the first clause matches. Put specific clauses first.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links