cpp/error/unexpected handler:修订间差异

来自cppreference.com
P12bot留言 | 贡献
Use {{lc}}. Update links. Various fixes.
Fruderica留言 | 贡献
无编辑摘要
第1行: 第1行:
{{tr_note}}
{{cpp/title|unexpected_handler}}
{{cpp/title|unexpected_handler}}
{{cpp/error/navbar}}
{{cpp/error/navbar}}
{{dcl begin}}
{{dcl begin}}
{{dcl header | exception}}
{{dcl header | exception}}
{{dcl | notes={{mark deprecated}} |
{{dcl | =|
typedef void (*unexpected_handler)();
typedef void (*unexpected_handler)();
}}
}}
{{dcl end}}
{{dcl end}}


{{tr|{{tt|std::unexpected_handler}}函数指针类型(指针到函数带任何参数并返回void),这是安装和查询的功能{{lc|std::set_unexpected}}{{lc|std::get_unexpected}},并呼吁通过{{lc|std::unexpected}}.|{{tt|std::unexpected_handler}} is the function pointer type (pointer to function that takes no arguments and returns void), which is installed and queried by the functions {{lc|std::set_unexpected}} and {{lc|std::get_unexpected}} and called by {{lc|std::unexpected}}.}}
{{tt|std::unexpected_handler}} 函数指针类型(指不参数并返),{{lc|std::set_unexpected}} {{lc|std::get_unexpected}} ,并{{lc|std::unexpected}}


{{tr|C + +实现提供了一个默认{{tt|std::unexpected_handler}}功能这就要求{{c|std::terminate()}}。如果空指针是安装手段{{lc|std::set_terminate}}),实现可能会恢复默认处理程序,而不是.|The C++ implementation provides a default {{tt|std::unexpected_handler}} function, which calls {{c|std::terminate()}}. If the null pointer value is installed (by means of {{lc|std::set_terminate}}), the implementation may restore the default handler instead.}}
C++ 实现提供默认{{tt|std::unexpected_handler}} ,{{c|std::terminate()}} 。空指针值({{lc|std::}} ),实现可恢复默认处理


{{tr|用户定义的{{tt|std::unexpected_handler}}预计终止程序抛出一个异常。如果它抛出一个异常,可能遇到下三种情况之一|A user-defined {{tt|std::unexpected_handler}} is expected to either terminate the program or throw an exception. If it throws an exception, one of the following three situations may be encountered:}}
用户定义的 {{tt|std::unexpected_handler}} 终止程序或抛出异常。它抛出异常,可能遇到下三种情况之一:


1) {{tr|{{tt|std::unexpected_handler}}满足动态例外,范,违反了新的例外是允许逃跑的功能和堆栈平仓继续|the exception thrown by {{tt|std::unexpected_handler}} satisfies the dynamic exception specification that was violated earlier. The new exception is allowed to escape the function and stack unwinding continues.}}
1) {{tt|std::unexpected_handler}} 满足动态规允许逃继续


2) {{tr|抛出的异常的{{tt|std::unexpected_handler}}仍然违反的异常规范|the exception thrown by {{tt|std::unexpected_handler}} still violates the exception specification:}}
2) {{tt|std::unexpected_handler}} 仍然违异常规


{{tr|2A),但是,异常规允许{{lc|std::bad_exception}}:抛出的异常对象被销毁,{{lc|std::bad_exception}}是通过C + +运行时抛出,而不是.|2a) however, the exception specification allows {{lc|std::bad_exception}}: the thrown exception object is destroyed, and {{lc|std::bad_exception}} is constructed by the C++ runtime and thrown instead.}}
,异常规允许 {{lc|std::bad_exception}} : 抛出的异常对象,{{lc|std::bad_exception}} 抛出


{{tr|2B)的例外不允许{{lc|std::bad_exception}}:{{c|std::terminate()}}被称为.|2b) the exception specification does not allow {{lc|std::bad_exception}}: {{c|std::terminate()}} is called.}}
规不允许 {{lc|std::bad_exception}} :{{c|std::terminate()}}


===另请参阅===
===参阅===
{{dsc begin}}
{{dsc begin}}
{{dsc inc | cpp/error/dsc unexpected}}
{{dsc inc | cpp/error/dsc unexpected}}
第30行: 第29行:
{{dsc end}}
{{dsc end}}


[[de:cpp/error/unexpected handler]]
deenesfritjaptru
[[en:cpp/error/unexpected handler]]
[[es:cpp/error/unexpected handler]]
[[fr:cpp/error/unexpected handler]]
[[it:cpp/error/unexpected handler]]
[[ja:cpp/error/unexpected handler]]
[[pt:cpp/error/unexpected handler]]
[[ru:cpp/error/unexpected handler]]

2017年8月27日 (日) 08:50的版本

在标头 <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++11 弃用)(C++17 移除)
违背动态异常说明时调用的函数
(函数) [编辑]
(C++11 弃用)(C++17 移除)
更改要被 std::unexpected 调用的函数
(函数) [编辑]
(C++11 弃用)(C++17 移除)
获得当前的 unexpected_handler
(函数) [编辑]