#include <iostream>
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 ExDivByZero();
break;
case 'b':
throw ExBadArgument();
break;
case 'c':
throw ExCannotOpen();
break;
}
} catch (Exception &e) {
std::cerr << e.origin() << std::endl;
}
}
return 0;
}
/* end */
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgRXhjZXB0aW9uIHsgcHVibGljOiB2aXJ0dWFsIGNoYXIgY29uc3QgKm9yaWdpbigpIHsgcmV0dXJuICJzb21ldGhpbmcgZWxzZS4iOyB9IH07CmNsYXNzIEV4RGl2QnlaZXJvIDogcHVibGljIEV4Y2VwdGlvbiB7IHB1YmxpYzogY2hhciBjb25zdCAqb3JpZ2luKCkgeyByZXR1cm4gIkRpdmlkZWQgYnkgemVyby4iOyB9IH07CmNsYXNzIEV4QmFkQXJndW1lbnQgOiBwdWJsaWMgRXhjZXB0aW9uIHsgcHVibGljOiBjaGFyIGNvbnN0ICpvcmlnaW4oKSB7IHJldHVybiAiQmFkIGFyZ3VtZW50LiI7IH0gfTsKY2xhc3MgRXhDYW5ub3RPcGVuIDogcHVibGljIEV4Y2VwdGlvbiB7IHB1YmxpYzogY2hhciBjb25zdCAqb3JpZ2luKCkgeyByZXR1cm4gIkNhbm5vdCBvcGVuLiI7IH0gfTsKCmludCBtYWluKCkgewogIGZvcig7OykgewogICAgY2hhciBjOwogICAgaWYgKHN0ZDo6Y2luID4+IGMsIGMgPT0gJ2QnKQogICAgICBicmVhazsKICAgIHRyeSB7CiAgICAgIHN3aXRjaCAoYykgewogICAgICBjYXNlICdhJzoKICAgICAgICB0aHJvdyBFeERpdkJ5WmVybygpOwogICAgICAgIGJyZWFrOwogICAgICBjYXNlICdiJzoKICAgICAgICB0aHJvdyBFeEJhZEFyZ3VtZW50KCk7CiAgICAgICAgYnJlYWs7CiAgICAgIGNhc2UgJ2MnOgogICAgICAgIHRocm93IEV4Q2Fubm90T3BlbigpOwogICAgICAgIGJyZWFrOwogICAgICB9CiAgICB9IGNhdGNoIChFeGNlcHRpb24gJmUpIHsKICAgICAgc3RkOjpjZXJyIDw8IGUub3JpZ2luKCkgPDwgc3RkOjplbmRsOwogICAgfQogIH0KICByZXR1cm4gMDsKfQovKiBlbmQgKi8K