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. |
| Defined in header <exception>
|
||
| typedef /*unspecified*/ exception_ptr; |
(C++11 起) | |
std::exception_ptr是一个可为空指针类型,管理一个被抛出的异常对象和拍摄的std::current_exception。 std::exception_ptr的一个实例传递给另一个函数,可能在另一个线程,可能会被重新抛出异常和处理的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.
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.
比较平等的,只有当他们都是null,或都指向相同的异常对象的两个实例
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是任何算术,枚举,或指针类型不能隐式转换。它转换为boolOriginal:
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
Output:
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. (函数) |