LearnFrenzy
Sign in Take a free test

Exception Handling · Exception Handling MCQ · Question 4

Order of catch blocks Answer, explanation & discussion

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

Why must catch (const std::out_of_range&) come before catch (const std::exception&)?

  • A Alphabetical order
  • B Handlers are tried in order and the first match wins; std::exception would catch out_of_range first, making the specific handler unreachable Correct
  • C It does not matter
  • D Compilers require it
Correct Answer: Option B

Compilers often warn about the unreachable handler.

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