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

std::unexpected_handler

Defined in header <exception>

typedef void (*unexpected_handler)();

(until C++17) (deprecated since C++11)

std::unexpected_handler函数指针类型%28指向函数,它不带参数并返回void%29,函数将安装并查询该函数。std::set_unexpectedstd::get_unexpected并被std::unexpected...

C++实现提供了一个默认的std::unexpected_handler函数,它调用std::terminate()。如果空指针值安装为%28,则使用std::set_unexpected%29,则实现可以还原默认处理程序。

用户定义的std::unexpected_handler将终止程序或抛出异常。如果抛出异常,可能会遇到以下三种情况之一:

1%29std::unexpected_handler满足之前违反的动态异常规范。允许新异常转义函数,堆栈展开继续进行。

2%29std::unexpected_handler仍然违反异常规范:

但是,异常规范允许std::bad_exception*已抛出的异常对象被销毁,并且std::bad_exception由C++运行时构造并抛出。

2B%29异常规范不允许std::bad_exception*std::terminate()叫做。

另见

unexpected (until C++17)

function called when dynamic exception specification is violated (function)

set_unexpected (until C++17)

changes the function to be called by std::unexpected (function)

get_unexpected (C++11)(until C++17)

obtains the current unexpected_handler (function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券