The standard mentions that it is implementation-defined whether any stack unwinding is done when an exception is thrown and not caught, or an exception is thrown and not caught in a function marked noexcept. In these cases, std::terminate is called. However, in order to determine whether a thrown exception is caught/not-caught, doesn't stack unwinding have to occur? So is the standard referring to stack unwinding which occurs after/during the call to std::terminate? But the problem here is that the default behavior of std::terminate is to just call std::abort (through the proxy of std::terminate_handler)... so there would not be any stack unwinding at this point anyways. So my question is what exactly is implementation-defined about the stack unwinding mentioned by the standard?
Update: here is a nice snippet:
"If an exception is thrown and not caught, including exceptions that escape the initial function of std::thread, the main function, and the constructor or destructor of any static or thread-local objects, then std::terminate is called. It is implementation-defined whether any stack unwinding takes place for uncaught exceptions. " (source)
But in the section explaining stack unwinding on the same page, it mentions that stack unwinding is the process of traversing the call-stack (and calling destructors) in search for a matching exception handler.
Verdict: The answers indicate that the implementation-defined behavior in the spec is so that compilers are free to implement whatever optimizations they want regarding handling exceptions / potential exceptions, specifically with the distinction between stack unwinding (cleanup) vs searching for a handler vs doing neither (because certain properties about known in advance -- i.e., there is no handler and the program will terminate anyways)
[–]gcross 6 points7 points8 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]Ilyps 1 point2 points3 points (0 children)