exception specification
De 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. |
Enumera las excepciones que una función puede lanzar directamente o indirectamente .
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.
Contenido |
[editar] Sintaxis
throw(typeid, typeid, ...)
|
(obsoleto) | ||||||||
[editar] Explicación
Si una función se declara con
T tipo indicado en su especificación de excepciones, la función puede lanzar excepciones de ese tipo o un tipo derivado de ella .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.
Si la función lanza una excepción del tipo que no figuran en su especificación de excepción, el std::unexpected función es llamada. La función predeterminada llama std::terminate, pero puede ser sustituido por una función proporcionada por el usuario (a través de std::set_unexpected), que pueden poner std::terminate o una excepción. Si la excepción lanzada desde std::unexpected es aceptado por la especificación de excepciones, desenredo de pila continúa como de costumbre. Si no lo es, pero std::bad_exception está permitido por la especificación de excepción, std::bad_exception es lanzada. De lo contrario, std::terminate se llama .
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.
[editar] Ejemplo
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() }

