◐ Shell
clean mode source ↗

std::exception_ptr - cppreference.com

De cppreference.com

Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.

La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí.

Definido en el archivo de encabezado <exception>

typedef /*unspecified*/ exception_ptr;

(desde C++11)

std::exception_ptr es anulable un puntero de tipo de tipo que maneja un objeto de excepción que ha sido lanzado y capturado con std::current_exception. Una instancia de std::exception_ptr se puede hacer pasar a otra función, posiblemente en otro hilo, donde la excepción puede ser relanzada y manipulados con una cláusula catch .

Original:

std::exception_ptr is a nullable pointer-like type that manages an exception object which has been thrown and captured with std::current_exception. An instance of std::exception_ptr may be passed to another function, possibly on another thread, where the exception may be rethrown and handled with a catch clause.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Default-construido std::exception_ptr es un puntero nulo, no apunta a un objeto de excepción .

Original:

Default-constructed std::exception_ptr is a null pointer, it does not point to 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.

Dos instancias de std::exception_ptr son iguales sólo si ambas son nulas o punto tanto en el objeto de excepción mismo .

Original:

Two instances of std::exception_ptr compare equal only if they are both null or both point at the same exception object.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

std::exception_ptr no es implícitamente convertible a cualquier aritmética, enumeración o tipo puntero. Es convertible a bool .

Original:

std::exception_ptr is not implicitly convertible to any arithmetic, enumeration, or pointer type. It is convertible to bool.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

El objeto de excepción que hace referencia una std::exception_ptr sigue siendo válida siempre y cuando no se mantiene al menos un std::exception_ptr que lo está haciendo referencia: std::exception_ptr es un puntero compartido propiedad inteligente .

Original:

The exception object referenced by an std::exception_ptr remains valid as long as there remains at least one std::exception_ptr that is referencing it: std::exception_ptr is a shared-ownership smart pointer.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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"

Ver también