This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.

313. set_terminate and set_unexpected question

Section: [terminate] Status: NAD Submitter: Judy Ward Opened: 2001-04-03 Last modified: 2017-02-03

Priority: Not Prioritized

View all other issues in [terminate].

View all issues with NAD status.


According to section of the standard, std::terminate() is supposed to call the terminate_handler in effect immediately after evaluating the throw expression.

Question: what if the terminate_handler in effect is itself std::terminate?

For example:

  #include <exception>

  int main () {
      throw 5;
      return 0;

Is the implementation allowed to go into an infinite loop?

I think the same issue applies to std::set_unexpected.

Proposed resolution:


Infinite recursion is to be expected: users who set the terminate handler to terminate are explicitly asking for terminate to call itself.