Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::terminate

      From cppreference.com
      <cpp‎ |error
       
       
      Diagnostics library
       
      Defined in header<exception>
      void terminate();
      (until C++11)
      [[noreturn]]void terminate()noexcept;
      (since C++11)

      std::terminate() is called by the C++ runtime when the program cannot continue for any of the following reasons:

      1) Anexception is thrown and not caught (it is implementation-defined whether any stack unwinding is done in this case).
      2) A function directly invoked by the exception handling mechanism while handling an exception that has not yet been caught exits via an exception (e.g. a destructor of some local object, or a copy constructor constructing a catch-clause parameter).
      3) The constructor or the destructor of a staticor thread-local(since C++11) object throws an exception.
      4) A function registered withstd::atexitorstd::at_quick_exit(since C++11) throws an exception.
      5) Adynamic exception specification is violated and the default handler forstd::unexpected is executed.
      6) A non-default handler forstd::unexpected throws an exception that violates the previously violated dynamic exception specification, if the specification does not includestd::bad_exception.
      (until C++17)
      7) Anoexcept specification is violated (it is implementation-defined whether any stack unwinding is done in this case).
      8)std::nested_exception::rethrow_nested is called for an object that isn't holding a captured exception.
      9) An exception is thrown from the initial function ofstd::thread.
      10) A joinablestd::thread is destroyed or assigned to.
      11)std::condition_variable::wait,std::condition_variable::wait_until, orstd::condition_variable::wait_for fails to reach its postcondition (e.g. if relocking the mutex throws).
      (since C++11)
      12) A function invoked by aparallel algorithm exits via an uncaught exception and theexecution policy specifies termination.
      (since C++17)

      std::terminate() may also be called directly from the program.

      Whenstd::terminate is called due to a thrown exception, an implicit try/catch handler is considered active. Thus, callingstd::current_exception will return the thrown exception.

      In any case,std::terminate calls the currently installedstd::terminate_handler. The defaultstd::terminate_handler callsstd::abort.

      If a destructor reset the terminate handler during stack unwinding and the unwinding later led toterminate being called, the handler that was installed at the end of the throw expression is the one that will be called. (note: it was ambiguous whether re-throwing applied the new handlers)

      (until C++11)

      If a destructor reset the terminate handler during stack unwinding, it is unspecified which handler is called if the unwinding later led toterminate being called.

      (since C++11)

      [edit]Notes

      If the handler mechanism is not wanted, e.g. because it requires atomic operations which may bloat binary size, a direct call tostd::abort is preferred when terminating the program abnormally.

      Some compiler intrinsics, e.g.__builtin_trap (gcc, clang, and icc) or__debugbreak (msvc), can be used to terminate the program as fast as possible.

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2111C++11effect of callingstd::set_terminate during stack
      unwinding differs from C++98 and breaks some ABIs
      made unspecified

      [edit]See also

      the type of the function called bystd::terminate
      (typedef)[edit]
      causes abnormal program termination (without cleaning up)
      (function)[edit]
      (C++26)
      pauses the running program when called
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/error/terminate&oldid=173424"

      [8]ページ先頭

      ©2009-2025 Movatter.jp