#include <iostream>
#include <new>
class Exception { public: virtual char const *origin() { return "something else."; } };
class ExDivByZero : public Exception { public: char const *origin() { return "Divided by zero."; } };
class ExBadArgument : public Exception { public: char const *origin() { return "Bad argument."; } };
class ExCannotOpen : public Exception { public: char const *origin() { return "Cannot open."; } };
int main() {
for(;;) {
char c;
if (std::cin >> c, c == 'd')
break;
try {
switch (c) {
case 'a':
throw (new ExDivByZero());
case 'b':
throw (new ExBadArgument());
case 'c':
throw (new ExCannotOpen());
}
} catch (Exception *e) {
std::cerr << e->origin() << std::endl;
delete e;
} catch (std::bad_alloc dmy) {
std::cerr << "bad_aloc." << std::endl;
/* eating */
}
}
}
/* end */
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bmV3PgoKY2xhc3MgRXhjZXB0aW9uIHsgcHVibGljOiB2aXJ0dWFsIGNoYXIgY29uc3QgKm9yaWdpbigpIHsgcmV0dXJuICJzb21ldGhpbmcgZWxzZS4iOyB9IH07CmNsYXNzIEV4RGl2QnlaZXJvIDogcHVibGljIEV4Y2VwdGlvbiB7IHB1YmxpYzogY2hhciBjb25zdCAqb3JpZ2luKCkgeyByZXR1cm4gIkRpdmlkZWQgYnkgemVyby4iOyB9IH07CmNsYXNzIEV4QmFkQXJndW1lbnQgOiBwdWJsaWMgRXhjZXB0aW9uIHsgcHVibGljOiBjaGFyIGNvbnN0ICpvcmlnaW4oKSB7IHJldHVybiAiQmFkIGFyZ3VtZW50LiI7IH0gfTsKY2xhc3MgRXhDYW5ub3RPcGVuIDogcHVibGljIEV4Y2VwdGlvbiB7IHB1YmxpYzogY2hhciBjb25zdCAqb3JpZ2luKCkgeyByZXR1cm4gIkNhbm5vdCBvcGVuLiI7IH0gfTsKIAppbnQgbWFpbigpIHsKICBmb3IoOzspIHsKICAgIGNoYXIgYzsKICAgIGlmIChzdGQ6OmNpbiA+PiBjLCBjID09ICdkJykKICAgICAgYnJlYWs7CiAgICB0cnkgewogICAgICBzd2l0Y2ggKGMpIHsKICA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