Espacios de nombres
Variantes
Acciones

std::current_exception

De cppreference.com
< cpp‎ | error
 
 
Biblioteca de servicios
 
Control de errores
Control de excepciones
current_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>
std::exception_ptr current_exception()
(desde C++11)
Si llama durante el manejo de excepciones (por lo general, en una cláusula catch), capta el objeto de excepción actual y crea un std::exception_ptr que contiene una referencia a ese objeto de excepción, o una copia de ese objeto de excepción (que es definido por la implementación si una copia es hizo)
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.
Si la implementación de esta función es necesario llamar al new y falla la llamada, el puntero devuelto tendrá una referencia a una instancia de 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.
Si la aplicación de esta función requiere para copiar el objeto de excepción capturado y su constructor de copia se produce una excepción, el puntero devuelto tendrá una referencia a la excepción lanzada. Si el constructor copia del objeto de excepción que también lanza, el puntero devuelto puede contener una referencia a una instancia de std::bad_exception para romper el bucle sin 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.
Si la función se llama cuando no es la excepción se está manejando, un std::exception_ptr vacía se devuelve .
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.

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.

[editar] Valor de retorno

Una instancia de std::exception_ptr contiene una referencia al objeto de excepción, o una copia del objeto de excepción, o en una instancia de std::bad_alloc o en una instancia 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.

[editar] Excepciones

Especificación noexcept:  
noexcept
  (desde C++11)

[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]
Produce la excepción de un std::exception_ptr.
(función) [editar]
Crea un std::exception_ptr de un objeto de excepción.
(plantilla de función) [editar]