certificate task /exceptions C++
Hello guys, I have exam task from C++ , what I don't understand class X { public: X(void) { cout << 1; } ~X(void) { cout << 2; } }; X *exec() { X *x = new X(); throw string("0"); return x; } int main(void) { X *x; try { delete exec(); } catch(string &s) { cout << s; } return 0; } Question: nr1. What happens in try{ } branch ? - how is possible to run function exec() using delete operator? This function starts new object after call. How is possible to "delete" unexisting object, before its called. its like "lock the draver with the key inside" nr2. What does it mean X *exec() {body of function} as far as I remmember correct answer should be 102, but, when I compile its 10, it means that destructor isn't called at all.