Challenge 2: Observing a Destructor Fire During Stack Unwinding — Possible Solution ==================================================================== #include #include class Noisy { public: ~Noisy() { std::cout << "Noisy destroyed" << std::endl; } }; void risky() { Noisy n; std::cout << "Before throw" << std::endl; throw std::runtime_error("boom"); std::cout << "This never prints" << std::endl; } int main() { try { risky(); } catch (const std::exception &e) { std::cout << "Caught in main: " << e.what() << std::endl; } return 0; } Output: Before throw Noisy destroyed Caught in main: boom WHY THIS WORKS AS AN ANSWER ------------------------------ "Noisy destroyed" prints BEFORE "Caught in main" -- confirming the chapter's own stack-unwinding claim precisely: as the exception propagates out of risky() looking for a matching catch, n's destructor runs automatically during that unwinding process, before control actually reaches the catch block in main. This happens with no explicit cleanup code written anywhere in risky() itself -- the destructor firing is entirely automatic, exactly the RAII-during- unwinding mechanism the chapter describes.