LearnFrenzy
Sign in Take a free test

Exception Handling · Exercise 1 of 4

Exception Handling Exception Handling MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on C++ exception handling: try/catch/throw, the standard exception hierarchy, catch order, rethrowing, stack unwinding, noexcept, constructors, destructors and exception safety. Pick an option to check your answer instantly.

Question 1 Easy

What is the main advantage of exceptions over returning error codes?

A They are always faster
B Errors cannot be silently ignored, and the code that detects an error is separated from the code that handles it
C They avoid destructors
D They work only in main
Question page & discussion
Question 2 Easy

After a catch block finishes, where does the program continue?

A At the throw statement
B After the last catch block of that try statement
C At the start of the try block
D The program ends
Question page & discussion
Question 3 Easy

Why is catch (const std::exception& e) preferred to catch (std::exception e)?

A It is shorter
B It avoids copying and slicing, so the derived exception's what() and data are kept
C Values cannot be caught
D It catches more types
Question page & discussion
Question 4 Medium

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
C It does not matter
D Compilers require it
Question page & discussion
Question 5 Easy

Which handler catches exceptions of any type, including throw 42;?

A catch (std::exception& e)
B catch (...)
C catch (auto e)
D catch (void)
Question page & discussion
Question 6 Medium

Inside catch (const std::exception& e), what is the difference between throw; and throw e;?

A None
B throw; rethrows the original exception with its real type; throw e; throws a new copy of type std::exception (sliced)
C throw e; is not allowed
D throw; ends the program
Question page & discussion
Question 7 Easy

What happens to local objects of the functions an exception passes through?

A They leak
B They are destroyed (their destructors run), in reverse order of construction
C They are copied to the handler
D Nothing until the program ends
Question page & discussion
Question 8 Easy

What happens if an exception propagates out of main without being caught?

A It is ignored
B std::terminate is called and the program aborts
C main returns 0
D It is printed and the program continues
Question page & discussion
Question 9 Medium

What happens if an exception escapes a function declared noexcept?

A The exception is ignored
B std::terminate is called
C It becomes a warning
D The caller catches it normally
Question page & discussion
Question 10 Medium

Why must destructors not let exceptions escape?

A Destructors cannot contain try
B They are noexcept by default, and a second exception during stack unwinding would call std::terminate
C It is slower
D It is allowed and common
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links