gpt4 book ai didi

c++ - 除了重新抛出 std::exception_ptr 之外,我还能做什么

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:43:00 25 4
gpt4 key购买 nike

我有一个 std::exception_ptr 类型的对象,我想在它上面调用 what(),但似乎没有办法做到这一点(如本答案中所述:How do I make a call to what() on std::exception_ptr)。

在互联网上搜索后,似乎除了重新抛出它并在 std::exception& 中捕获它之外我无法对它做任何事情。

这对我来说有点奇怪,但我想检查一下:std::exception_ptr 可以做什么,然后重新抛出它以获得期望的细节?

C++14或其他版本的C++有什么变化

最佳答案

不幸的是,没有。该标准仅保证 std::exception_ptr 的以下内容:

18.8.5 Exception propagation

1 The type exception_ptr can be used to refer to an exception object.

2 exception_ptr shall satisfy the requirements of NullablePointer (17.6.3.3).

3 Two non-null values of type exception_ptr are equivalent and compare equal if and only if they refer to the same exception.

4 The default constructor of exception_ptr produces the null value of the type.

5 exception_ptr shall not be implicitly convertible to any arithmetic, enumeration, or pointer type.

7 For purposes of determining the presence of a data race, operations on exception_ptr objects shall access and modify only the exception_ptr objects themselves and not the exceptions they refer to.

此外,注意到 here ,

Performing any other operation on the object (such as dereferencing it), if at all supported by the library implementation, causes undefined behavior.

关于c++ - 除了重新抛出 std::exception_ptr 之外,我还能做什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41168218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com