#include <memory>
#include <stdexcept>
#include <iostream>
struct Object
{
Object() { std::cout << "An Object is created!\n"; }
~Object() { std::cout << "An Object is destroyed!\n"; }
};
class MyClass
{
std::unique_ptr<Object> _object;
void methodThatWillCauseException()
{
throw std::runtime_error("ERROR: gratuitous exception");
}
public:
MyClass() : _object(new Object)
{
methodThatWillCauseException();
}
};
int main()
{
try {
MyClass Instance;
}
catch (std::exception& ex)
{
std::cout << ex.what() << '\n';
}
}
I2luY2x1ZGUgPG1lbW9yeT4KI2luY2x1ZGUgPHN0ZGV4Y2VwdD4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IE9iamVjdCAKewogICAgT2JqZWN0KCkgeyBzdGQ6OmNvdXQgPDwgIkFuIE9iamVjdCBpcyBjcmVhdGVkIVxuIjsgfQogICAgfk9iamVjdCgpIHsgc3RkOjpjb3V0IDw8ICJBbiBPYmplY3QgaXMgZGVzdHJveWVkIVxuIjsgfQp9OwoKY2xhc3MgTXlDbGFzcwp7CiAgICBzdGQ6OnVuaXF1ZV9wdHI8T2JqZWN0PiBfb2JqZWN0OwoKICAgIHZvaWQgbWV0aG9kVGhhdFdpbGxDYXVzZUV4Y2VwdGlvbigpCiAgICB7CiAgICAgICAgdGhyb3cgc3RkOjpydW50aW1lX2Vycm9yKCJFUlJPUjogZ3JhdHVpdG91cyBleGNlcHRpb24iKTsKICAgIH0KcHVibGljOgoKICAgIE15Q2xhc3MoKSA6IF9vYmplY3QobmV3IE9iamVjdCkKICAgIHsKICAgICAgICBtZXRob2RUaGF0V2lsbENhdXNlRXhjZXB0aW9uKCk7CiAgICB9Cn07CgppbnQgbWFpbigpCnsKICAgIHRyeSB7CiAgICAgICAgTXlDbGFzcyBJbnN0YW5jZTsKICAgIH0KICAgIGNhdGNoIChzdGQ6OmV4Y2VwdGlvbiYgZXgpCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8IGV4LndoYXQoKSA8PCAnXG4nOwogICAgfQp9