A destructor throws while the stack is already unwinding from another exception. What is the outcome in C++11 and later?
Correct answer
C. std::terminate is called, because two active exceptions cannot propagate at once
13 views
C. std::terminate is called, because two active exceptions cannot propagate at once
13 views
Destructors are implicitly noexcept, so an exception escaping one during unwinding calls std::terminate instead of propagating. Even with no exception in flight, throwing from a destructor is hazardous because cleanup often runs on partially destroyed objects. Destructors should catch and log, or expose an explicit close() that can report failure.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.