std::set_terminate

Header: <exception>

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.

# Declarations

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)

# Parameters

# Return value

The previously-installed terminate handler, or a null pointer value if none was installed.

# Example

#include <cstdlib>
#include <exception>
#include <iostream>
 
int main()
{
    std::set_terminate([]()
    {
        std::cout << "Unhandled exception\n" << std::flush;
        std::abort();
    });
    throw 1;
}

# See also