#include <iostream>
using namespace std;
#define IF_THREW(EXPR, EXC) \
try \
{ \
EXPR; \
} \
catch (EXC)
#define OR_THREW(EXC) \
catch (EXC)
int computeFoo(int n)
{
if (n == 0)
{
throw "div by 0!";
}
if (n < 0)
{
throw -1;
}
return 100 / n;
}
int main(void)
{
int foo;
IF_THREW(foo = computeFoo(10), const char* excmsg)
{
cout << "exception: " << excmsg << endl;
}
cout << foo << endl;
IF_THREW(foo = computeFoo(0), const char* excmsg)
{
cout << "exception: " << excmsg << endl;
}
IF_THREW(foo = computeFoo(-1), const char* excmsg)
{
cout << "exception: " << excmsg << endl;
}
OR_THREW(int)
{
cout << "exception: negative" << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgSUZfVEhSRVcoRVhQUiwgRVhDKSBcCnRyeSBcCnsgXAogIEVYUFI7IFwKfSBcCmNhdGNoIChFWEMpCgojZGVmaW5lIE9SX1RIUkVXKEVYQykgXApjYXRjaCAoRVhDKQoKaW50IGNvbXB1dGVGb28oaW50IG4pCnsKICBpZiAobiA9PSAwKQogIHsKICAgIHRocm93ICJkaXYgYnkgMCEiOwogIH0KICBpZiAobiA8IDApCiAgewogICAgdGhyb3cgLTE7CiAgfQoKICByZXR1cm4gMTAwIC8gbjsKfQoKaW50IG1haW4odm9pZCkKewogIGludCBmb287CgogIElGX1RIUkVXKGZvbyA9IGNvbXB1dGVGb28oMTApLCBjb25zdCBjaGFyKiBleGNtc2cpCiAgewogICAgY291dCA8PCAiZXhjZXB0aW9uOiAiIDw8IGV4Y21zZyA8PCBlbmRsOwogIH0KCiAgY291dCA8PCBmb28gPDwgZW5kbDsKCiAgSUZfVEhSRVcoZm9vID0gY29tcHV0ZUZvbygwKSwgY29uc3QgY2hhciogZXhjbXNnKQogIHsKICAgIGNvdXQgPDwgImV4Y2VwdGlvbjogIiA8PCBleGNtc2cgPDwgZW5kbDsKICB9CgogIElGX1RIUkVXKGZvbyA9IGNvbXB1dGVGb28oLTEpLCBjb25zdCBjaGFyKiBleGNtc2cpCiAgewogICAgY291dCA8PCAiZXhjZXB0aW9uOiAiIDw8IGV4Y21zZyA8PCBlbmRsOwogIH0KICBPUl9USFJFVyhpbnQpCiAgewogICAgY291dCA8PCAiZXhjZXB0aW9uOiBuZWdhdGl2ZSIgPDwgZW5kbDsKICB9CgogIHJldHVybiAwOwp9Cg==