std::unexpected_handler

定义于头文件 <exception>
typedef void (*unexpected_handler)();
(C++11 中弃用)
(C++17 中移除)

std::unexpected_handler 是函数指针类型(指向不接收参数并返回 void 的函数),它为函数 std::set_unexpected 所安装,为 std::get_unexpected 所查询,并为 std::unexpected 所调用。

C++ 实现提供默认的 std::unexpected_handler 函数,它调用 std::terminate() 。若安装空指针值(用 std::set_unexpected ),则实现可以替代地恢复默认处理函数。

期待用户定义的 std::unexpected_handler 终止程序或抛出异常。若它抛出异常,则可能遇到下列三种情况之一:

1) std::unexpected_handler 所抛的异常满足之前被违背的动态异常规定。则允许新异常逃出函数并继续栈回溯。

2) std::unexpected_handler 所抛的异常仍然违背动态异常规定:

2a) 然而,异常规定允许 std::bad_exception : C++ 运行时销毁抛出的异常对象,并构造 std::bad_exception 替代地抛出。

2b) 异常规定不允许 std::bad_exception :调用 std::terminate()

参阅

(C++17 前)
违背动态异常规定时调用的函数
(函数)
(C++17 前)
更改要被 std::unexpected 调用的函数
(函数)
(C++11)(C++17 前)
获得当前的 unexpected_handler
(函数)

版本历史

  • (当前 | 先前 2017年8月27日 (日) 01:50Fruderica讨论 | 贡献. . (1,483字节) (-1,677). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:07P12bot讨论 | 贡献 . . (3,160字节) (-70). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 14:44P12bot讨论 | 贡献 . . (3,230字节) (+289). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 12:17P12讨论 | 贡献 . . (2,941字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 07:00TranslationBot讨论 | 贡献. . (2,941字节) (-31). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:25P12讨论 | 贡献 . . (2,972字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 13:00TranslationBot讨论 | 贡献. . (2,972字节) (+2,972). . (Translated from the English version using Google Translate)