Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/error/set terminate"

From cppreference.com
< cpp‎ | error
m (paste fix)
m (Text replace - "{{noexcept" to "{{unreviewed noexcept")
Line 26: Line 26:
 
{{rev begin}}
 
{{rev begin}}
 
{{rev | until=c++11 | (none)}}
 
{{rev | until=c++11 | (none)}}
{{rev | since=c++11 | {{noexcept}}}}
+
{{rev | since=c++11 | {{unreviewed noexcept}}}}
 
{{rev end}}
 
{{rev end}}
  

Revision as of 11:42, 31 March 2017

 
 
 
Defined in header <exception>

Makes f the new global terminate handler function and returns the previously installed std::terminate_handler.

This function is thread-safe. Every call to std::set_terminate synchronizes-with (see std::memory_order) the subsequent std::set_terminate and std::get_terminate

(since C++11)

Contents

Parameters

f - pointer to function of type std::terminate_handler, or null pointer

Return value

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

Exceptions

(none) (until C++11)
noexcept specification:  
noexcept
  
(since C++11)

Example

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

Possible output:

Unhandled exception
bash: line 7:  7743 Aborted                 (core dumped) ./a.out

See also

function called when exception handling fails
(function) [edit]
obtains the current terminate_handler
(function) [edit]
the type of the function called by std::terminate
(typedef) [edit]