std::current_exception
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. |
Déclaré dans l'en-tête <exception> | ||
std::exception_ptr current_exception() | (depuis C++11) | |
Si elle est appelée lors de la gestion des exceptions (généralement, dans une clause catch), saisit l'objet de l'exception en cours et crée une std::exception_ptr qui contient une référence à cet objet exception, ou à une copie de cet objet d'exception (il est défini par l'implémentation si une copie est fait)
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.
Si la mise en œuvre de cette fonction nécessite un appel à new et l'appel échoue, le pointeur retourné contiendra une référence à une instance de 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.
Si la mise en œuvre de cette fonction nécessite de copier l'objet d'exception capturé et son constructeur de copie lève une exception, le pointeur retourné contiendra une référence à l'exception levée. Si le constructeur de copie de l'objet exception levée jette aussi, le pointeur renvoyé peut contenir une référence à une instance de std::bad_exception pour briser la boucle sans fin .
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.
Si la fonction est appelée lorsque aucune exception n'est en cours de traitement, un std::exception_ptr vide est retournée .
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.
Sommaire |
[modifier]Paramètres
(Aucun)
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.
[modifier]Retourne la valeur
Une instance de std::exception_ptr contient une référence à l'objet exception, ou une copie de l'objet exception, ou à une instance de std::bad_alloc ou à une instance de 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.
[modifier]Exceptions
[modifier]Exemple
#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(conststd::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
Résultat :
Caught exception "basic_string::at"
[modifier]Voir aussi
(C++11) | type de pointeur partagé pour manipuler des objets d'exception 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) | lève l'exception d'un 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. (fonction) |
(C++11) | crée un std::exception_ptr à partir d'un objet d'exception 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. (fonction générique) |