c++ - Terminate application AND call the destructors of local objects -


i have objects on stack in main function:

int main(...) {    cfoo foo;    cbar bar; } 

also, have function, keeps track of errors in application:

void err(std::string msg) {    somehowlogerrormessage(msg);    exit(1); } 

err function useful when have report fatal error. log error , terminate application - cannot recover after such errors. however, terminating "exit()" not invoke foo , bar destructors - behavior, expected (but wrong). "abort()" doesn't either. also, i cannot use exceptions catch them in main(). there other way implement err function so, terminates app , correctly cleans stack objects? or should somehow redesign error handling?

thanks!


p.s. way, can't send wm_quit message main window? not winapi, app pure win32 , err() function can handle main window. work?

not without exceptions or returning err way callstack. need unwind stack.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -