std::rethrow_exception — cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Déclaré dans l'en-tête <exception> |
||
|
|
(depuis C++11) | |
Lance l'objet exception précédemment capturée, cité par le pointeur exception p .
Original:
Throws the previously captured exception object, referred to by the exception pointer p.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Paramètres
| p | - | non nulle std::exception_ptr Original: non-null std::exception_ptr The text has been machine-translated via Google Translate. |
Retourne la valeur
(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.
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(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
Résultat :
Caught exception "basic_string::at"
Voir aussi
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. (typedef) [edit] | |
capture l'exception en cours dans un std::exception_ptr Original: captures the current exception in a std::exception_ptr The text has been machine-translated via Google Translate. (fonction) [edit] | |