|
747 | 747 | exception object and will have effect should that object be rethrown.%
|
748 | 748 | \indextext{exception handling!handler!match|)}%
|
749 | 749 | \indextext{exception handling!handler|)}
|
750 |
| - |
751 |
| -\rSec1[except.special]{Special functions} |
752 |
| - |
753 |
| -\rSec2[except.special.general]{General} |
754 |
| - |
755 |
| -\pnum |
756 |
| -The function \tcode{std::terminate}\iref{except.terminate} |
757 |
| -is used by the exception |
758 |
| -handling mechanism for coping with errors related to the exception handling |
759 |
| -mechanism itself. |
760 |
| -The function \tcode{std::uncaught_exceptions}\iref{uncaught.exceptions} |
761 |
| -reports how many exceptions are uncaught in the current thread. |
762 |
| -The function \tcode{std::current_exception}\iref{propagation} and the class |
763 |
| -\tcode{std::nested_exception}\iref{except.nested} can be used by a program to |
764 |
| -capture the currently handled exception. |
765 |
| - |
766 |
| -\rSec2[except.terminate]{The \tcode{std::terminate} function} |
767 |
| - |
768 |
| -\pnum |
769 |
| -\indextext{\idxcode{terminate}}% |
770 |
| -Some errors in a program cannot be recovered from, such as when an exception |
771 |
| -is not handled or a \tcode{std::thread} object is destroyed while its thread |
772 |
| -function is still running. In such cases, |
773 |
| -the function \tcode{std::terminate}\iref{exception.terminate} is invoked. |
774 |
| -\begin{note} |
775 |
| -These situations are: |
776 |
| -\indextext{\idxcode{terminate}!called}% |
777 |
| -\begin{itemize} |
778 |
| -\item% |
779 |
| -when the exception handling mechanism, after completing |
780 |
| -the initialization of the exception object |
781 |
| -but before |
782 |
| -activation of a handler for the exception\iref{except.throw}, |
783 |
| -calls a function that exits |
784 |
| -via an exception, or |
785 |
| - |
786 |
| -\item% |
787 |
| -when the exception handling mechanism cannot find a handler for a thrown exception\iref{except.handle}, or |
788 |
| - |
789 |
| -\item when the search for a handler\iref{except.handle} encounters the |
790 |
| -outermost block of a function |
791 |
| -with a non-throwing exception specification\iref{except.spec}, or |
792 |
| - |
793 |
| -\item% |
794 |
| -when the destruction of an object during stack unwinding\iref{except.ctor} |
795 |
| -terminates by throwing an exception, or |
796 |
| - |
797 |
| -\item% |
798 |
| -when initialization of a non-block |
799 |
| -variable with static or thread storage duration\iref{basic.start.dynamic} |
800 |
| -exits via an exception, or |
801 |
| - |
802 |
| -\item% |
803 |
| -when destruction of an object with static or thread storage duration exits |
804 |
| -via an exception\iref{basic.start.term}, or |
805 |
| - |
806 |
| -\item% |
807 |
| -when execution of a function registered with |
808 |
| -\tcode{std::atexit} or \tcode{std::at_quick_exit} |
809 |
| -exits via an exception\iref{support.start.term}, or |
810 |
| - |
811 |
| -\item% |
812 |
| -when a |
813 |
| -\grammarterm{throw-expression}\iref{expr.throw} |
814 |
| -with no operand attempts to rethrow an exception and no exception is being |
815 |
| -handled\iref{except.throw}, or |
816 |
| - |
817 |
| -\item% |
818 |
| -when the function \tcode{std::nested_exception::rethrow_nested} is called for an object |
819 |
| -that has captured no exception\iref{except.nested}, or |
820 |
| - |
821 |
| -\item% |
822 |
| -when execution of the initial function of a thread exits via |
823 |
| -an exception\iref{thread.thread.constr}, or |
824 |
| - |
825 |
| -\item% |
826 |
| -for a parallel algorithm whose \tcode{ExecutionPolicy} specifies such |
827 |
| -behavior\iref{execpol.seq,execpol.par,execpol.parunseq}, |
828 |
| -when execution of an element access function\iref{algorithms.parallel.defns} |
829 |
| -of the parallel algorithm exits via an exception\iref{algorithms.parallel.exceptions}, or |
830 |
| - |
831 |
| -\item% |
832 |
| -when the destructor or the move assignment operator is invoked on an object |
833 |
| -of type \tcode{std::thread} that refers to |
834 |
| -a joinable thread\iref{thread.thread.destr,thread.thread.assign}, or |
835 |
| - |
836 |
| -\item% |
837 |
| -when a call to a \tcode{wait()}, \tcode{wait_until()}, or \tcode{wait_for()} |
838 |
| -function on a condition variable\iref{thread.condition.condvar,thread.condition.condvarany} |
839 |
| -fails to meet a postcondition, or |
840 |
| - |
841 |
| -\item% |
842 |
| -when a callback invocation exits via an exception |
843 |
| -when requesting stop on |
844 |
| -a \tcode{std::stop_source} or |
845 |
| -a \tcode{std::in\-place_stop_source}\iref{stopsource.mem,stopsource.inplace.mem}, |
846 |
| -or in the constructor of |
847 |
| -\tcode{std::stop_callback} or |
848 |
| -\tcode{std::inplace_stop_callback}\iref{stopcallback.cons,stopcallback.inplace.cons} |
849 |
| -when a callback invocation exits via an exception, or |
850 |
| - |
851 |
| -\item% |
852 |
| -when a \tcode{run_loop} object is destroyed |
853 |
| -that is still in the \tcode{running} state\iref{exec.run.loop}, or |
854 |
| - |
855 |
| -\item% |
856 |
| -when \tcode{unhandled_stopped} is called on |
857 |
| -a \tcode{with_awaitable_senders<T>} object\iref{exec.with.awaitable.senders} |
858 |
| -whose continuation is not a handle to a coroutine |
859 |
| -whose promise type has an \tcode{unhandled_stopped} member function. |
860 |
| - |
861 |
| -\end{itemize} |
862 |
| - |
863 |
| -\end{note} |
864 |
| - |
865 |
| -\pnum |
866 |
| -\indextext{\idxcode{terminate}}% |
867 |
| -In the situation where no matching handler is found, it is |
868 |
| -\impldef{stack unwinding before invocation of \tcode{std::terminate}} |
869 |
| -whether or not the stack is unwound |
870 |
| -before \tcode{std::terminate} is invoked. |
871 |
| -In the situation where the search for a handler\iref{except.handle} encounters the |
872 |
| -outermost block of a function |
873 |
| -with a non-throwing exception specification\iref{except.spec}, it is |
874 |
| -\impldef{whether stack is unwound before invoking the function \tcode{std::terminate} |
875 |
| -when a \tcode{noexcept} specification is violated} |
876 |
| -whether the stack is unwound, unwound partially, or not unwound at all |
877 |
| -before the function \tcode{std::terminate} is invoked. |
878 |
| -In all other situations, the stack shall not be unwound before |
879 |
| -the function \tcode{std::terminate} |
880 |
| -is invoked. |
881 |
| -An implementation is not permitted to finish stack unwinding |
882 |
| -prematurely based on a determination that the unwind process |
883 |
| -will eventually cause an invocation of the function |
884 |
| -\tcode{std::terminate}. |
885 | 750 | \indextext{exception handling|)}
|
0 commit comments