std::exception_ptr
Материал из 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. |
| Заголовочный файл <exception>
|
||
| typedef /*unspecified*/ exception_ptr; |
(начиная с C++11) | |
std::exception_ptr является обнуляемого указатель, как типа, который управляет исключения объекта, который был брошен и захватил с std::current_exception. Экземпляр std::exception_ptr может быть передана другой функции, возможно, на другой поток, в котором исключение может быть вызвано повторно и обрабатывается с уловом пункта.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.
You can help to correct and verify the translation. Click here for instructions.
По умолчанию построенных
std::exception_ptr является нулевым указателем, она не указывает на объект исключения.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.
You can help to correct and verify the translation. Click here for instructions.
Два экземпляра
std::exception_ptr равными только тогда, когда они оба нулевые или оба точки, в тот же объект исключения.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.
You can help to correct and verify the translation. Click here for instructions.
std::exception_ptr не неявно преобразовываться в любые арифметические, перечисление или тип указателя. Это, конвертируемых в 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.
You can help to correct and verify the translation. Click here for instructions.
Исключение объекта на который ссылается
std::exception_ptr остается действительным до тех пор, пока остается хотя бы одна std::exception_ptr, которые на него ссылаются: std::exception_ptr является общей собственности смарт-указатель.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.
You can help to correct and verify the translation. Click here for instructions.
[править] Пример
#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
Вывод:
Caught exception "basic_string::at"
[править] См. также
| (C++11) |
создает std::exception_ptr от объекта исключения 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. (шаблон функции) |
| (C++11) |
captures the current exception in a std::exception_ptr (функция) |
| (C++11) |
бросает исключение из 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. (функция) |