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() }

