std::current_exception
Aus 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. |
definiert in Header <exception>
|
||
std::exception_ptr current_exception() |
(seit C++11) | |
Wenn während der Ausnahmebehandlung (in der Regel in einem catch Klausel) genannt wird, erfasst die aktuelle Ausnahme Objekt und erstellt eine std::exception_ptr, die einen Verweis hält an dieser Ausnahme-Objekt oder auf eine Kopie dieser Ausnahme-Objekt (es ist die Implementierung definiert, wenn eine Kopie ist hergestellt)
Original:
If called during exception handling (typically, in a catch clause), captures the current exception object and creates an std::exception_ptr that holds a reference to that exception object, or to a copy of that exception object (it is implementation-defined if a copy is made)
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.
Wenn die Implementierung dieser Funktion erfordert einen Aufruf new und der Aufruf fehlschlägt, wird der zurückgegebene Zeiger einen Verweis auf eine Instanz std::bad_alloc
Original:
If the implementation of this function requires a call to new and the call fails, the returned pointer will hold a reference to an instance of std::bad_alloc
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.
Wenn die Implementierung dieser Funktion benötigt, um das aufgenommene Ausnahme-Objekt kopieren und die Kopie Konstruktor eine Ausnahme auslöst, wird die zurückgegebene Zeiger einen Verweis auf die Ausnahme ausgelöst. Wenn die Kopie Konstruktor des geworfenen Exception-Objekt wirft auch, kann die zurückgegebene Zeiger einen Verweis auf eine Instanz std::bad_exception um die Endlosschleife zu brechen .
Original:
If the implementation of this function requires to copy the captured exception object and its copy constructor throws an exception, the returned pointer will hold a reference to the exception thrown. If the copy constructor of the thrown exception object also throws, the returned pointer may hold a reference to an instance of std::bad_exception to break the endless loop.
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.
Wenn die Funktion aufgerufen wird, wenn keine Ausnahme gehandhabt wird, wird ein leerer std::exception_ptr zurückgegeben .
Original:
If the function is called when no exception is being handled, an empty std::exception_ptr is returned.
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.
Inhaltsverzeichnis |
[Bearbeiten] Parameter
(None)
Original:
(none)
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.
[Bearbeiten] Rückgabewert
Eine Instanz std::exception_ptr hält einen Verweis auf die Ausnahme-Objekt oder eine Kopie des Exception-Objekt oder auf eine Instanz std::bad_alloc oder zu einer Instanz von std::bad_exception .
Original:
An instance of std::exception_ptr holding a reference to the exception object, or a copy of the exception object, or to an instance of std::bad_alloc or to an instance of std::bad_exception.
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.
[Bearbeiten] Ausnahmen
[Bearbeiten] Beispiel
#include <iostream> #include <string> #include <exception> #include <stdexcept> void handle_eptr(std::exception_ptr eptr) // passing by value is ok { try { if (eptr != std::exception_ptr()) { std::rethrow_exception(eptr); } } catch(const std::exception& e) { std::cout << "Caught exception \"" << e.what() << "\"\n"; } } int main() { std::exception_ptr eptr; try { std::string().at(1); // this generates an std::out_of_range } catch(...) { eptr = std::current_exception(); // capture } handle_eptr(eptr); } // destructor for std::out_of_range called here, when the eptr is destructed
Output:
Caught exception "basic_string::at"
[Bearbeiten] Siehe auch
(C++11) |
teilte Zeigertyp für den Umgang mit Exception-Objekte Original: shared pointer type for handling exception objects The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (typedef) |
(C++11) |
wirft die Ausnahme von einem std::exception_ptr Original: throws the exception from an std::exception_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktion) |
(C++11) |
schafft eine std::exception_ptr von einer Ausnahme-Objekt Original: creates an std::exception_ptr from an exception object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) |