Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Thrown exceptions that are not explicitly caught subject the a program to several implementation-dependent issues. C++2004, section 15.5.1 "The std::terminate() function3 "Handling an Exception", says:

...when the exception handling mechanism cannot find a handler for a thrown exception (15.3).

In such cases, If no matching handler is found in a program, the function std::terminate() is called (18.7.3). In the situation where no matching handler is found, it is implementation-defined ; whether or not the stack is unwound before this call to std::terminate() is called. In all other situations, the stack shall not be unwound before std::terminate() is called. An implementation is not permitted to finish stack unwinding prematurely based on a determination that the unwind process will eventually cause a call to std::terminate(implementation-defined (15.5.1).

Consequently you should take steps to prevent std::terminate() from being invoked for two reasons. First because it involves implementation-defined behavior. 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.

...