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