#include <iostream>
#include <vector>
#include <string>
//#include <unistd.h>
int open() {
return 42;
}
void close(int handle) {}
struct Context {
int handle;
std::vector<std::string> errors;
};
class File {
Context &ctx_;
public:
File(Context &ctx) : ctx_(ctx)
{
try {
ctx.handle = open();
} catch(...) {
ctx_.errors.push_back("Unable to open file");
}
}
~File() {
try {
close(ctx_.handle);
} catch(...) {
ctx_.errors.push_back("An error occured");
}
}
};
int main() {
Context ctx;
{
File f(ctx);
}
for (auto e : ctx.errors)
std::cout << e << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgovLyNpbmNsdWRlIDx1bmlzdGQuaD4KCmludCBvcGVuKCkgewoJcmV0dXJuIDQyOwp9Cgp2b2lkIGNsb3NlKGludCBoYW5kbGUpIHt9CgpzdHJ1Y3QgQ29udGV4dCB7CglpbnQgaGFuZGxlOwoJc3RkOjp2ZWN0b3I8c3RkOjpzdHJpbmc+IGVycm9yczsKfTsKCmNsYXNzIEZpbGUgewoJQ29udGV4dCAmY3R4XzsKcHVibGljOgoJRmlsZShDb250ZXh0ICZjdHgpIDogY3R4XyhjdHgpCgl7CgkJdHJ5IHsKCQkJY3R4LmhhbmRsZSA9IG9wZW4oKTsKCQl9IGNhdGNoKC4uLikgewoJCQljdHhfLmVycm9ycy5wdXNoX2JhY2soIlVuYWJsZSB0byBvcGVuIGZpbGUiKTsKCQl9CQkKCX0KCX5GaWxlKCkgewoJCXRyeSB7CgkJCWNsb3NlKGN0eF8uaGFuZGxlKTsKCQl9IGNhdGNoKC4uLikgewoJCQljdHhfLmVycm9ycy5wdXNoX2JhY2soIkFuIGVycm9yIG9jY3VyZWQiKTsKCQl9Cgl9Cn07CgppbnQgbWFpbigpIHsKCUNvbnRleHQgY3R4OwoJewoJCUZpbGUgZihjdHgpOwoJfQoJZm9yIChhdXRvIGUgOiBjdHguZXJyb3JzKQoJCXN0ZDo6Y291dCA8PCBlIDw8IHN0ZDo6ZW5kbDsKCXJldHVybiAwOwp9