According to the terms of the MECPP 11. At the beginning: The destructor will be called in both cases. The first is to delete an object under normal circumstances, such as an object beyond the scope or explicitly delete. The second is that an abnormal processing system deletes an object during the stack-unwinding of abnormal transmission. In both cases, the abnormality may not be in an active state when calling the destructuring function. Unfortunately there is no way to distinguish these two situations within the descent function. So when you write a function function, you must conserve a deactivation. Because if it is activated while an exception is activated, the destruction function also throws an exception and causes the program control to transfer to the destructor, and C will call the Terminate function. The role of this function is as indicated by its name: it terminates the run of your program, and it is terminated immediately, and even the local object is not released. Almost make people feel very puzzled, so write the following Code to help understand:
#include
Class class_test {public: class_test (void) {} ~ class_test (void) {// throw bad_alloc (); // If you throw out an exception will call Terminate () cout << "~ class_test () .... "<< Endl; cin.get ();} private:}; void funteest0 (void) {class_test obj; cout <<" f0 ... "<< Endl; throw bad_alloc (); cout << "FUNTEST0 () ..." << Endl;} void funteest1 (void) {class_test obj; cout << "f1 ....." << Endl; funteest0 (); cout << "FUNTEST1 ( ) ... "<< Endl;} int main () try {class_test obj; funtest1 (); cin.get (); return 0;} catch (bad_alloc) {cout << E.What () << Endl; cin.get ();