#include <iostream>
#include <string>
#include <exception>
using namespace std;
class MyException : public exception
{
public:
// exception specifications (throw lists) are deprecated.
// use the noexcept keyword to indicate a function doesn't throw.
virtual const char* what() const noexcept
{
return "Something bad happened";
}
};
class Test
{
public:
void goesWrong() // exception specifications are deprecated
{
throw MyException();
}
};
int main()
{
Test test;
try
{
test.goesWrong();
}
catch (exception &e)
{
cout << "First catch: ";
cout << e.what() << '\n';
}
try
{
test.goesWrong();
}
catch (exception e)
{
cout << "Second catch: ";
cout << e.what() << '\n';
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8ZXhjZXB0aW9uPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIE15RXhjZXB0aW9uIDogcHVibGljIGV4Y2VwdGlvbgp7CnB1YmxpYzoKICAgIC8vIGV4Y2VwdGlvbiBzcGVjaWZpY2F0aW9ucyAodGhyb3cgbGlzdHMpIGFyZSBkZXByZWNhdGVkLgogICAgLy8gdXNlIHRoZSBub2V4Y2VwdCBrZXl3b3JkIHRvIGluZGljYXRlIGEgZnVuY3Rpb24gZG9lc24ndCB0aHJvdy4KICAgIHZpcnR1YWwgY29uc3QgY2hhciogd2hhdCgpIGNvbnN0IG5vZXhjZXB0ICAgIAogICAgewogICAgICAgIHJldHVybiAiU29tZXRoaW5nIGJhZCBoYXBwZW5lZCI7CiAgICB9Cn07CgpjbGFzcyBUZXN0CnsKcHVibGljOgogICAgdm9pZCBnb2VzV3JvbmcoKSAgLy8gZXhjZXB0aW9uIHNwZWNpZmljYXRpb25zIGFyZSBkZXByZWNhdGVkCiAgICB7CiAgICAgICAgdGhyb3cgTXlFeGNlcHRpb24oKTsKICAgIH0KfTsKCmludCBtYWluKCkKewogICAgVGVzdCB0ZXN0OwoKICAgIHRyeQogICAgewogICAgICAgIHRlc3QuZ29lc1dyb25nKCk7CiAgICB9CiAgICBjYXRjaCAoZXhjZXB0aW9uICZlKQogICAgew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