exception specification
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
列出的功能的异常可能直接或间接地扔.
Original:
Lists the exceptions that a function might directly or indirectly throw.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 语法
throw(typeid, typeid, ...)
|
(过时了) | ||||||||
[编辑] 解释
如果一个函数被声明为与它的异常规范中列出的
T类型,函数可能抛出异常,该类型或从它派生的类型.Original:
If a function is declared with type
T listed in its exception specification, the function may throw exceptions of that type or a type derived from it.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
如果函数抛出一个异常,它的异常规范中未列出的类型,功能std::unexpected被调用。默认的函数调用std::terminate,但它可能会被替换由用户提供的功能(通过std::set_unexpected),可致电std::terminate或者抛出一个异常。如果所接受的异常规范,从std::unexpected抛出的异常堆栈平仓像往常一样继续。如果不是这样,但std::bad_exception所允许的异常规范,std::bad_exception被抛出。否则,std::terminate被称为.
Original:
If the function throws an exception of the type not listed in its exception specification, the function std::unexpected is called. The default function calls std::terminate, but it may be replaced by a user-provided function (via std::set_unexpected) which may call std::terminate or throw an exception. If the exception thrown from std::unexpected is accepted by the exception specification, stack unwinding continues as usual. If it isn't, but std::bad_exception is allowed by the exception specification, std::bad_exception is thrown. Otherwise, std::terminate is called.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
class X {}; class Y {}; class Z : public X {}; class W {}; void f() throw(X, Y) { int n = 0; if (n) throw X(); // OK if (n) throw Z(); // also OK throw W(); // will call std::unexpected() }

