std::current_exception
Da cppreference.com.
![]() | Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <exception> | ||
std::exception_ptr current_exception() | (dal C++11) | |
Se viene chiamato durante la gestione delle eccezioni (in genere, in una clausola catch), cattura l'oggetto corrente eccezione e crea un std::exception_ptr che contiene un riferimento a tale oggetto di eccezione, o ad una copia di tale oggetto eccezione (è definito dall'implementazione se una copia è fatto)
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.
Se l'implementazione di questa funzione richiede una chiamata al new e la chiamata non riesce, il puntatore restituito terrà un riferimento a un'istanza di 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.
Se l'implementazione di questa funzione richiede di copiare l'oggetto eccezione catturato e la sua costruttore di copia genera un'eccezione, il puntatore restituito terrà un riferimento all'eccezione generata. Se il costruttore copia dell'oggetto eccezione generata tiri anche, il puntatore restituito può contenere un riferimento a un'istanza di std::bad_exception per interrompere il ciclo infinito.
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.
Se la funzione viene chiamata quando non fa eccezione viene gestita, un std::exception_ptr vuoto viene restituito.
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.
Indice |
[modifica]Parametri
(Nessuno)
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.
[modifica]Valore di ritorno
Un'istanza di std::exception_ptr in possesso di un riferimento all'oggetto eccezione, o di una copia dell'oggetto eccezione, o di un'istanza di std::bad_alloc o un'istanza di 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.
[modifica]Eccezioni
[modifica]Esempio
#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
Output:
Caught exception "basic_string::at"
[modifica]Vedi anche
(C++11) | puntatore di tipo comune per la gestione di oggetti eccezione 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) | genera l'eccezione da 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. (funzione) |
(C++11) | crea un std::exception_ptr da un oggetto eccezione 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. (funzione di modello) |