首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::set_terminate

Defined in header <exception>

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)

二次

代码语言:javascript
复制
#include <iostream>
#include <cstdlib>
#include <exception>
 
int main()
{
    std::set_terminate([](){ std::cout << "Unhandled exception\n"; std::abort();});
    throw 1;
}

二次

可能的产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券