std::current_exception
Da 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. |
Definido no cabeçalho <exception> | ||
std::exception_ptr current_exception() | (desde C++11) | |
Se for chamado durante o tratamento de exceção (normalmente, em uma cláusula catch), capta o objeto de exceção atual e cria um std::exception_ptr que contém uma referência a esse objeto de exceção, ou de uma cópia do que objeto de exceção (que é definida pela implementação se uma cópia é feita)
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.
You can help to correct and verify the translation. Click here for instructions.
Se a implementação desta função requer uma chamada para new ea chamada falhar, o ponteiro retornado irá realizar uma referência a uma instância 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.
You can help to correct and verify the translation. Click here for instructions.
Se a implementação desta função requer para copiar o objeto de exceção capturada e seu construtor cópia lança uma exceção, o ponteiro retornado irá realizar uma referência para a exceção lançada. Se o construtor de cópia do objeto exceção lançada também lança, o ponteiro retornado pode conter uma referência a uma instância de std::bad_exception para quebrar o loop infinito.
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.
You can help to correct and verify the translation. Click here for instructions.
Se a função é chamada quando nenhuma exceção está sendo tratado, uma std::exception_ptr vazio é retornado.
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.
You can help to correct and verify the translation. Click here for instructions.
Índice |
[editar]Parâmetros
(Nenhum)
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
Uma instância de std::exception_ptr mantendo uma referência para o objeto de exceção, ou uma cópia do objeto de exceção, ou a uma instância do std::bad_alloc ou a uma instância do 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.
You can help to correct and verify the translation. Click here for instructions.
[editar]Exceções
[editar]Exemplo
#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(conststd::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
Saída:
Caught exception "basic_string::at"
[editar]Veja também
(C++11) | tipo ponteiro compartilhado para manusear objetos de exceção 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) |
(C++11) | lança a exceção de um std::exception_ptr Original: throws the exception from an 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. (função) |
(C++11) | cria uma std::exception_ptr a partir de um objeto de exceção Original: creates an std::exception_ptr from 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. (modelo de função) |