◐ Shell
clean mode source ↗

exception specification – cppreference.com

Aus cppreference.com

<metanoindex/>

Führt die Ausnahmen, die eine Funktion direkt oder indirekt auslösen könnte .

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.

Syntax

throw(typeid, typeid, ...) (veraltet)

Erklärung

Wenn eine Funktion mit Typ T in seiner Ausnahmespezifikation aufgeführten erklärt wird, kann die Funktion Ausnahmen aus dieser Art oder einen Typ daraus abgeleiteten .

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.

Wenn die Funktion löst eine Ausnahme des Typs nicht in ihrer Exception-Spezifikation enthalten ist, wird die Funktion std::unexpected genannt. Die Standard-Funktion aufruft std::terminate, aber es kann von einem Benutzer bereitgestellte Funktion (via std::set_unexpected), die std::terminate nennen kann oder eine Ausnahme ersetzt werden. Wenn die Ausnahme vom std::unexpected geworfen von der Exception-Spezifikation angenommen wird, weiterhin stapeln Abwickeln wie gewohnt. Wenn es nicht, doch wird durch die std::bad_exception Ausnahmespezifikation erlaubt wird std::bad_exception geworfen. Andernfalls wird std::terminate genannt .

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.

Beispiel

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

Siehe auch