#include <iostream>
#include <exception>
#include <stdexcept>
void universal_exception_handler(std::exception_ptr e)
{
try
{
std::rethrow_exception(e);
}
catch (const std::logic_error& e)
{
std::cout << "logic_error" << std::endl;
}
catch (const std::runtime_error& e)
{
std::cout << "runtime_error" << std::endl;
}
}
void foo()
{
throw std::logic_error{""};
}
void bar()
{
throw std::runtime_error{""};
}
int main()
{
try
{
foo();
}
catch (...)
{
universal_exception_handler(std::current_exception());
}
try
{
bar();
}
catch (...)
{
universal_exception_handler(std::current_exception());
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZXhjZXB0aW9uPgojaW5jbHVkZSA8c3RkZXhjZXB0PgoKdm9pZCB1bml2ZXJzYWxfZXhjZXB0aW9uX2hhbmRsZXIoc3RkOjpleGNlcHRpb25fcHRyIGUpCnsKCXRyeQoJewoJCXN0ZDo6cmV0aHJvd19leGNlcHRpb24oZSk7Cgl9CgljYXRjaCAoY29uc3Qgc3RkOjpsb2dpY19lcnJvciYgZSkKCXsKCQlzdGQ6OmNvdXQgPDwgImxvZ2ljX2Vycm9yIiA8PCBzdGQ6OmVuZGw7Cgl9CgljYXRjaCAoY29uc3Qgc3RkOjpydW50aW1lX2Vycm9yJiBlKQoJewoJCXN0ZDo6Y291dCA8PCAicnVudGltZV9lcnJvciIgPDwgc3RkOjplbmRsOwoJfQp9Cgp2b2lkIGZvbygpCnsKCXRocm93IHN0ZDo6bG9naWNfZXJyb3J7IiJ9Owp9Cgp2b2lkIGJhcigpCnsKCXRocm93IHN0ZDo6cnVudGltZV9lcnJvcnsiIn07Cn0KCmludCBtYWluKCkKewoJdHJ5Cgl7CgkJZm9vKCk7Cgl9CgljYXRjaCAoLi4uKQoJewoJCXVuaXZlcnNhbF9leGNlcHRpb25faGFuZGxlcihzdGQ6OmN1cnJlbnRfZXhjZXB0aW9uKCkpOwoJfQoJCgl0cnkKCXsKCQliYXIoKTsKCX0KCWNhdGNoICguLi4pCgl7CgkJdW5pdmVyc2FsX2V4Y2VwdGlvbl9oYW5kbGVyKHN0ZDo6Y3VycmVudF9leGNlcHRpb24oKSk7Cgl9Cn0K