std::uncaught_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. |
Defined in header <exception>
|
||
bool uncaught_exception(); |
||
Detecta si el subproceso actual tiene un objeto de excepción en vivo, es decir, ha sido una excepción y no ha entrado una cláusula catch coincidente, std::terminate o std::unexpected. En otras palabras, std::uncaught_exception detecta si desenredo de pila está en curso .
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 veces es más seguro para producir una excepción, incluso mientras std::uncaught_exception() == true. Por ejemplo, si las excepciones son capturadas e ignorados en un destructor, que no se puede propagar fuera de él y no dará lugar a 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.
Contenido |
[editar] Parámetros
(Ninguno)
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.
[editar] Valor de retorno
true si desenredo de pila está actualmente en curso en este hilo .
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.
[editar] Excepciones
[editar] Ejemplo
#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"; throw std::runtime_error("test exception"); } catch (const std::exception& e) { std::cout << "Exception caught: " << e.what() << '\n'; } }
Output:
Exception thrown ~Foo() called during stack unwinding Exception caught: test exception ~Foo() called normally
[editar] Ver también
función llamada cuando falla el control de excepciones 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. (función) | |
(C++11) |
puntero compartido tipo para la manipulación de objetos de excepción 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) |