abort, terminate or exit?

后端 未结 6 694
心在旅途
心在旅途 2021-01-29 20:31

What\'s the difference between those three, and how shall I end program in case of exception which I can\'t handle properly?

6条回答
  •  萌比男神i
    2021-01-29 20:36

    quick_exit() !

    If your program is multi-threaded, then calling exit() will most likely result in a crash because global/static std::thread objects will be attempted to destruct without exiting their threads.

    If you want to return an error code and exit the program (more or less) normally, call quick_exit() in multi-threaded programs. For abnormal termination (without a possibility for you to specify the error code), abort() or std::terminate() can be called.

    Note: quick_exit() has not been supported by MSVC++ until version 2015 .

提交回复
热议问题