#include <exception>
typedef enum foo_Result {
FOO_OK,
FOO_ERROR1,
FOO_ERROR2,
FOO_UNKNOWN
} foo_Result;
struct MyException1 { };
struct MyException2 { };
foo_Result lippincott()
try
{
try
{
if (std::exception_ptr eptr = std::current_exception())
{
std::rethrow_exception(eptr);
}
else
{
return FOO_UNKNOWN;
}
}
catch (const MyException1&)
{
return FOO_ERROR1;
}
catch (const MyException2&)
{
return FOO_ERROR2;
}
catch (...)
{
return FOO_UNKNOWN;
}
}
catch (...)
{
return FOO_UNKNOWN;
}
//////////////////////////
void Snafuscate(bool andDie)
{
if (andDie)
{
throw MyException1();
}
}
foo_Result foo_snafuscate(bool andDie)
{
try
{
Snafuscate(andDie);
return FOO_OK;
}
catch (...)
{
return lippincott();
}
}
#include <iostream>
int main()
{
foo_Result r1 = foo_snafuscate(false);
if (r1 == FOO_OK) std::cout << "r1 == FOO_OK\n";
foo_Result r2 = foo_snafuscate(true);
if (r2 != FOO_OK) std::cout << "r2 != FOO_OK (r2 == " << r2 << ")\n";
}
I2luY2x1ZGUgPGV4Y2VwdGlvbj4KCnR5cGVkZWYgZW51bSBmb29fUmVzdWx0IHsKICAgIEZPT19PSywKICAgIEZPT19FUlJPUjEsCiAgICBGT09fRVJST1IyLAogICAgRk9PX1VOS05PV04KfSBmb29fUmVzdWx0OwoKc3RydWN0IE15RXhjZXB0aW9uMSB7IH07CnN0cnVjdCBNeUV4Y2VwdGlvbjIgeyB9OwoKZm9vX1Jlc3VsdCBsaXBwaW5jb3R0KCkKdHJ5CnsKICAgIHRyeQogICAgewogICAgICAgIGlmIChzdGQ6OmV4Y2VwdGlvbl9wdHIgZXB0ciA9IHN0ZDo6Y3VycmVudF9leGNlcHRpb24oKSkKICAgICAgICB7CiAgICAgICAgICAgIHN0ZDo6cmV0aHJvd19leGNlcHRpb24oZXB0cik7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBGT09fVU5LTk9XTjsKICAgICAgICB9C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