ProgrammingHardProduct-company placement · C++

In C++, a destructor throws an exception while the stack is already being unwound because of another exception. What happens?

  1. A. The new exception replaces the old one
  2. B. std::terminate is called
  3. C. The second exception is silently ignored
  4. D. Both exceptions are delivered to the nearest catch (...)

Correct answer: B. std::terminate is called

Two exceptions cannot be in flight at once; if a destructor called during unwinding lets an exception escape, the runtime calls std::terminate. That is why destructors should not throw.

More OOP with C++ and Java questions

Exams that ask this topic