나는 stack unwinding
에 대한 지식을 얻으 려하고 this page을 보았습니다. 아래 예제를 통해 알 수 있습니다. 이 cpp 코드 조각은 어떻게 덤프합니까?
#include <iostream>
using namespace std;
struct E {
const char* message;
E(const char* arg) : message(arg) { }
};
void my_terminate() {
cout << "Call to my_terminate" << endl;
};
struct A {
A() { cout << "In constructor of A" << endl; }
~A() {
cout << "In destructor of A" << endl;
throw E("Exception thrown in ~A()");
}
};
struct B {
B() { cout << "In constructor of B" << endl; }
~B() { cout << "In destructor of B" << endl; }
};
int main() {
set_terminate(my_terminate);
try {
cout << "In try block" << endl;
A a;
B b;
throw("Exception thrown in try block of main()");
}
catch (const char* e) {
cout << "Exception: " << e << endl;
}
catch (...) {
cout << "Some exception caught in main()" << endl;
}
cout << "Resume execution of main()" << endl;
}
내가 컴파일 할 때이 코어 덤프있어 그러나 그램 ++ 다음과 같이 /*clang++*.The 출력은 다음과 같습니다
In try block
In constructor of A
In constructor of B
In destructor of B
In destructor of A
Call to my_terminate
已放弃 (核心已转储) #core dump
사람이 나에게 몇 가지 힌트를 줄 수 있습니까?
글쎄, 당신의'terminate'는 ... 프로그램을 종료하지 않았습니다! – avakar