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. |
<metanoindex/>
<tbody> </tbody>| Dclar dans l'en-tte <exception>
|
||
std::exception_ptr current_exception() |
(depuis C++11) | |
Si elle est appele lors de la gestion des exceptions (gnralement, dans une clause
catch), saisit l'objet de l'exception en cours et cre une std::exception_ptr qui contient une rfrence cet objet exception, ou une copie de cet objet d'exception (il est dfini par l'implmentation 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 ncessite un appel
new et l'appel choue, le pointeur retourn contiendra une rfrence une instance de std::bad_allocOriginal:
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_allocThe 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 ncessite de copier l'objet d'exception captur et son constructeur de copie lve une exception, le pointeur retourn contiendra une rfrence l'exception leve. Si le constructeur de copie de l'objet exception leve jette aussi, le pointeur renvoy peut contenir une rfrence 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 appele lorsque aucune exception n'est en cours de traitement, un std::exception_ptr vide est retourne .
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.
Paramtres
(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.
Retourne la valeur
Une instance de std::exception_ptr contient une rfrence 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.
Exceptions
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
Rsultat :
Caught exception "basic_string::at"
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) |
lve 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) |
cre 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 gnrique) |