Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Elaborated description.

Thrown exceptions that are not explicitly caught subject a running program to several implementation-dependent issues. C++2004, defined behavior culminating in abnormal termination. According to section 15.3 "Handling an Exception" , saysof C++2003 [ISO/IEC 14882-2003]:

If no matching handler is found in a program, the function std::terminate() is called; whether or not the stack is unwound before this call to std::terminate() is implementation-defined (15.5.1).

The effects of std::terminate() are to call the terminate_handler function in effect immediately after evaluating the throw-expression. The default terminate_handler calls std::abort(), which has the effect of causing abnormal process termination to occur. Abnormal process termination is the typical vector for denial of service attacks. A user-defined terminate_handler may be set by calling std::set_terminate(). In either case, std::terminate() must not return. Attempting to return from a user-defined terminate_handler or from a SIGABRT handler invoked as a result of calling std::abort() leads to undefined behavior.

Consequently, programs Consequently you should take steps to prevent std::terminate() from being invoked for at least two reasons. First because it :

  1. If the stack is not unwound then destructors of local objects are not invoked, acquired system-wide or application-wide resources may not be released, file buffers are not flushed, database transactions are not committed or rolled back, etc.
  2. Since failing to catch an exception involves implementation-defined behavior, to comply MSC14-CPP. Do not introduce unnecessary platform dependencies.

Rather, programs should catch all exceptions and attempt to recover at the earliest opportunity. Under the rare circumstances when recovery is not feasible (for example, when a logic error is detected), programs should gracefully terminate after indicating the nature of the problem to the operator. Second, if the stack is not unwound on your platform, than RAII is violated. That is, destructors are not called, allocated memory is not freed, opened files are not flushed and closed, etc. See also ERR04-CPP. Choose an appropriate termination strategy.

...