◐ Shell
clean mode source ↗

std::rethrow_exception - cppreference.com

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.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

Elemento definito nell'header

<exception>

[[noreturn]] void rethrow_exception( std::exception_ptr p )

(dal C++11)

Genera l'oggetto eccezione catturata in precedenza, cui fa riferimento il puntatore eccezione 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.

Parametri

p -

non nullo std::exception_ptr

Original:

non-null std::exception_ptr

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

Valore di ritorno

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

Esempio

[edit]

#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

Output:

Caught exception "basic_string::at"

Vedi anche

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) [modifica]
captures the current exception in a std::exception_ptr
(funzione) [modifica]