Hard
A function-try-block on a constructor
What does this program print?
main.cpp
#include <iostream>
#include <stdexcept>
struct Member {
Member() { throw std::runtime_error("member"); }
};
struct Owner {
Member m;
Owner() try : m() {
std::cout << "body ";
} catch (const std::exception& e) {
std::cout << "handler(" << e.what() << ") ";
// the handler does not throw
}
};
int main() {
try {
Owner o;
std::cout << "constructed ";
} catch (const std::exception& e) {
std::cout << "main(" << e.what() << ")";
}
std::cout << "\n";
}115 of 117 in C++