Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can I do with an std::exception_ptr other than rethrowing it

I have an object of type std::exception_ptr, and I want to call what() on it, but it seems there is no way to do this (As explaned in this answer: How do I make a call to what() on std::exception_ptr).

After searching over internet, it seems that I can not do anything with it other than re-throwing it and catching it in a std::exception& to be able to do this.

It is a bit strange for me, but I want to check: What can do with a std::exception_ptr other then re-throwing it to get the detail of expectation?

Is there any change in C++14 or other versions of C++

like image 658
mans Avatar asked Dec 15 '16 15:12

mans


1 Answers

Unfortunately, no. The standard only guarantees the following for 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.

Additionally, noted here,

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

like image 99
lcs Avatar answered Oct 22 '22 22:10

lcs