std::set_terminate
STD:设置[医]终止
Defined in header | | |
---|---|---|
std::terminate_handler set_terminate( std::terminate_handler f | | |
制造f
新的全局终止处理程序函数,并返回先前安装的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) |
---|
参数
f | - | pointer to function of type std::terminate_handler, or null pointer |
---|
返回值
以前安装的终止处理程序,如果没有安装,则为空指针值。
例外
(none) | (until C++11) |
---|---|
noexcept specification: noexcept | (since C++11) |
例
二次
#include <iostream>
#include <cstdlib>
#include <exception>
int main()
{
std::set_terminate([](){ std::cout << "Unhandled exception\n"; std::abort(}
throw 1;
}
二次
可能的产出:
二次
Unhandled exception
bash: line 7: 7743 Aborted (core dumped) ./a.out
二次
另见
terminate | function called when exception handling fails (function) |
---|---|
get_terminate (C++11) | obtains the current terminate_handler (function) |
terminate_handler | the type of the function called by std::terminate (typedef) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。