Defined in header <exception> | ||
|---|---|---|
std::terminate_handler set_terminate( std::terminate_handler f ) throw(); | (until C++11) | |
std::terminate_handler set_terminate( std::terminate_handler f ) noexcept; | (since C++11) |
Makes f the new global terminate handler function and returns the previously installed std::terminate_handler. f shall terminate execution of the program without returning to its caller, otherwise the behavior is undefined.
| This function is thread-safe. Every call to | (since C++11) |
| f | - | pointer to function of type std::terminate_handler, or null pointer |
The previously-installed terminate handler, or a null pointer value if none was installed.
#include <iostream>
#include <cstdlib>
#include <exception>
int main()
{
std::set_terminate([](){
std::cout << "Unhandled exception\n" << std::flush;
std::abort();
});
throw 1;
}Possible output:
Unhandled exception bash: line 7: 7743 Aborted (core dumped) ./a.out
| function called when exception handling fails (function) |
|
|
(C++11) | obtains the current terminate_handler (function) |
the type of the function called by std::terminate (typedef) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/error/set_terminate