abort, terminate or exit?

后端 未结 6 563
心在旅途
心在旅途 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条回答
  •  醉话见心
    2021-01-29 20:42

    • terminate() is automatically called when an exception occurs that cannot be handled. By default, terminate() calls abort(). You can set a custom handle with set_terminate() function.

      abort() sends the SIGABRT signal.

      exit() is not necessarily a bad thing. It successfully exits the application, and calls atexit() functions in LIFO order. I don't normally see this in C++ applications, however, I do see it in many unix based applications where it sends an exit code at the end. Usually a exit(0) indicates a successful run of the application.

提交回复
热议问题