Espacios de nombres
Variantes
Acciones

std::rethrow_exception

De cppreference.com
< cpp‎ | error
 
 
Biblioteca de servicios
 
Control de errores
Control de excepciones
rethrow_exception
(C++11)
Fallas del control de excepciones
(hasta C++17)
(hasta C++17)
(C++11)(hasta C++17)
(hasta C++17)
Códigos de error
Códigos de error
 
Definido en el archivo de encabezado <exception>
[[noreturn]] void rethrow_exception( std::exception_ptr p )
(desde C++11)
Lanza el objeto de excepción capturada anteriormente, referido por el puntero excepción 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.

Contenido

[editar] Parámetros

p -
no nulo std::exception_ptr
Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Valor de retorno

(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.

[editar] Ejemplo

#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

Salida:

Caught exception "basic_string::at"

[editar] Ver también

Tipo de puntero compartido para la manipulación de objetos de excepción.
(typedef) [editar]
Captura la excepción actual en un std::exception_ptr
(función) [editar]