std::uncaught_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> | ||
bool uncaught_exception(); | ||
Rileva se il thread corrente ha un oggetto vivo eccezione, che è, una è stata generata un'eccezione e non ancora entrati in una clausola corrispondente cattura, std::terminate o std::unexpected. In altre parole, std::uncaught_exception rileva se la rimozione dello stack è attualmente in corso.
Original:
Detects if the current thread has a live exception object, that is, an exception has been thrown and not yet entered a matching catch clause, std::terminate or std::unexpected. In other words, std::uncaught_exception detects if stack unwinding is currently in progress.
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.
A volte è sicuro per generare un'eccezione anche durante std::uncaught_exception()==true. Ad esempio, se le eccezioni sono catturati e ignorati in un distruttore, non possono propagare fuori di esso e non porterà ad std::terminate.
Original:
Sometimes it's safe to throw an exception even while std::uncaught_exception()==true. For example, if exceptions are caught and ignored in a destructor, they can't propagate out of it and won't lead to std::terminate.
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
true se la rimozione dello stack è attualmente in corso in questo thread.
Original:
true if stack unwinding is currently in progress in this thread.
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 <exception>#include <stdexcept> struct Foo { ~Foo(){if(std::uncaught_exception()){std::cout<<"~Foo() called during stack unwinding\n";}else{std::cout<<"~Foo() called normally\n";}}};int main(){ Foo f;try{ Foo f;std::cout<<"Exception thrown\n";throwstd::runtime_error("test exception");}catch(conststd::exception& e){std::cout<<"Exception caught: "<< e.what()<<'\n';}}
Output:
Exception thrown ~Foo() called during stack unwinding Exception caught: test exception ~Foo() called normally
[modifica]Vedi anche
funzione chiamata quando la gestione delle eccezioni non riesce Original: function called when exception handling fails 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) | 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) |