1-12-7 异常正常析构的证明

1.12-7 异常正常析构的证明

#include <iostream>
<!--more-->
#include <exception>

using namespace std;
class MyException : public logic_error
{
public:
MyException(const char *s) : logic_error(s) {}
~MyException() { cout << "the Exception has been destructed." << endl; }
};
class test
{
public:
void throwException() { throw MyException("hello, this is MyException."); }
};

int main(int argc, char const *argv[])
{
try
{
test t;
t.throwException();
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}

return 0;
}