exit( status ) terminates the process normally. a status value of 0 or
EXIT_SUCCESS indicates success, and any other value or the constant
EXIT_FAILURE is used to indicate an error. exit() performs following
operations. 1) Flushes unwritten buffered data. 2) Closes all open files.
3) Removes temporary files.
Abort will not do as much as exit, but using abort will dump core, if
the user has core dumps enabled. So as a rule of thumb, I’d use abort
if you’re so unsure about what’s gone wrong that the only way to get
useful information about it is by analysing a core dump.
assert just call abort.
std::terminate is what is automatically called in a C++ program when
there is an unhandled exception. This is essentially the C++ equivalent
to abort, assuming that you are reporting all your exceptional errors
by means of throwing exceptions. This calls a handler that is set by the
std::set_terminate function, which by default simply calls abort.
Catch the exceptions you can’t handle in main() and simply return from
there. This means that you are guaranteed that stack unwinding happens
correctly and all destructors are called.