Hard
Two destructors that throw
Compiled as C++17 or later, what does this program print before it exits (normally or otherwise)?
main.cpp
#include <iostream>
#include <stdexcept>
struct Throws {
~Throws() noexcept(false) { throw std::runtime_error("Throws"); }
};
struct Holder {
Throws t;
~Holder() { std::cout << "~Holder "; } // no exception specification written
};
struct Plain {
~Plain() { throw std::runtime_error("Plain"); } // no exception specification written
};
int main() {
try { Holder h; } catch (const std::exception& e) { std::cout << "caught " << e.what() << "\n"; }
try { Plain p; } catch (const std::exception& e) { std::cout << "caught " << e.what() << "\n"; }
}110 of 117 in C++