I have some objects on the stack in the main function:
int main(...) { CFoo foo; CBar bar; }
In addition, I have a function that tracks errors in my application:
void Err(std::string msg) { SomehowLogErrorMessage(msg); exit(1); }
The Err function is definitely useful when I have to report a fatal error. I simply register an error and terminate the application - after such errors it is impossible to recover. However, terminating with the "exit ()" function does not call the destructors foo and bar - the behavior that I really expected (but was wrong). "abort ()" doesn't help either. In addition, I cannot use exceptions to catch them in main (). Is there any other way to implement the Err function so that it terminates the application and correctly clears the stack objects? Or am I somehow redesigning my error handling?
Thanks!
ps By the way, can I send WM_QUIT message to my main window? I am not good at WinAPI, but my application is pure Win32, and my Err () function can get a handle to my main window. Will this work?
c ++ stack windows destructor exit
Sadsido
source share