#include <iostream>
#include <exception>
using std::cout;
using std::endl;
class test
{
public:
test()
{
cout<<"constructor called"<<endl;
}
~test()
{
cout<<"destructor called"<<endl;
}
void fun(int x)
{
throw x;
}
};
int main()
{
try
{
static test k;
k.fun(3);
}
catch(int k)
{
cout<<"exception handler"<<endl;
}
}
例外がスローされると、スタックの巻き戻しプロセス中に、静的オブジェクトやヒープ オブジェクトではなく、ローカル オブジェクトのみが破棄されると思います。これが本当なら、クラス (テスト) デストラクタが呼び出される理由がわかりません。ありがとう。