命名空间
变体
操作

std::make_exception_ptr

来自 cppreference.cn
< cpp‎ | error
定义于头文件 <exception>
template< class E >
std::exception_ptr make_exception_ptr( E e ) noexcept;
(C++11 起)
(C++26 起 constexpr)

创建一个 std::exception_ptr,持有对 e 的副本的引用。这相当于执行以下代码

try
{
    throw e;
}
catch(...)
{
    return std::current_exception();
}

目录

[edit] 参数

e - 要创建对其副本引用的异常对象

[edit] 返回值

一个 std::exception_ptr 实例,持有对 e 的副本的引用,或者一个 std::bad_alloc 实例,或者一个 std::bad_exception 实例 (参见 std::current_exception)。

[edit] 注解

参数通过值传递,并可能发生对象切片。

特性测试 Std 特性
__cpp_lib_constexpr_exceptions 202411L (C++26) constexpr 针对异常类型

[edit] 示例

[edit] 参见

在一个 std::exception_ptr 中捕获当前异常
(函数) [编辑]