Last active
February 23, 2017 14:18
-
-
Save dannas/ee9f1f81576388836ecd15eea0247652 to your computer and use it in GitHub Desktop.
When will stack undwinding take place?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When will the destructor of class C get called? | |
// 1. If we call exit? | |
// 2. If we call abort? | |
// 3. If we throw an exception? | |
// 4. If we throw an exception that won't be caught (comment out the try-catch statement) | |
// and thus invokes the terminate() handler? | |
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
class C { | |
public: | |
C() { cout << "ctor\n"; } | |
~C() { cout << "dtor\n"; } | |
}; | |
int f() { | |
C c; | |
// exit(0); // 1. | |
// abort(); // 2. | |
// throw 42; // 3. | |
} | |
int main() { | |
try { // 4. | |
f(); | |
} catch (...) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment