class ScopedShit
{
public:
ScopedShit() {
cout << "ScopedShit()" << endl;
}
~ScopedShit() {
cout << "~ScopedShit()" << endl;
}
};
void foo()
{
ScopedShit ss;
int x = 0;
int y = 5 / x;
}
int main()
{
__try {
foo();
}
__except(true) {
cout << "Continuing..." << endl;
}
}
Output:
ScopedShit()
Continuing...
I'm reading this article http://www.codeproject.com/Articles/2126/How-a-C-compiler-implements-exception-handling which explains:
But before it (the exception handler) calls the catch block (it knows the address of the catch block from funcinfo structure, see figure 4), it must perform stack unwinding: cleaning up the stack frames of the functions below this function's frame. Cleaning of the stack frame involves nice little intricacy: The exception handler must find all the local objects of the function alive on the frame at the time of the exception and call their destructors.
Am I missing something?
I believe you need to specify /EHa
at compile time for SEH exceptions to invoke C++ destructors.
If /EH is not specified, the compiler will catch structured and C++ exceptions, but will not destroy C++ objects that will go out of scope as a result of the exception.
See MSDN for further details.