If I compile this
The X object thrown by g() appears to get destructed twice. Is this right ? Or is there something very wrong with the program? Or is my compiler sick?Code:#include <iostream> #include <exception> using namespace std; class X { public: static int i; int count; X(){count = ++i; cout << "constructing X object " << count << endl;} ~X(){cout << "destructing X object " << count << endl;} }; int X::i = 0; void f() throw (X) { throw 1; } void g() { cout << "unexpected handler g() called\n"; throw X(); } int main() { set_unexpected(&g); try { f(); } catch (X) { cout << "caught exception X\n"; } catch (int) { cout << "caught exception int\n"; } return 0; }
Any ideas?