I found in several places on how a promise should be used references to copy_exception
, but I can not find it in the current FDIS. Is there an alternative way on how to use set_exception()
since those blogs?
For example here
void asyncFun(promise<int> intPromise)
{
int result;
try {
// calculate the result
intPromise.set_value(result);
} catch (MyException e) {
intPromise.set_exception(std::copy_exception(e)); // <- copy
}
}
I find std::current_exception()
here.
catch(...)
{
p.set_exception(std::current_exception());
}
Therefore my questions:
current_exception()
, even when I do not catch "...
"?copy_exception
?There is a different name for copy_exception
. copy_exception
was renamed late in the standardization process over confusion of what it actually did:
template<class E>
exception_ptr make_exception_ptr(E e) noexcept;
Effects: Creates an
exception_ptr
object that refers to a copy ofe
, ...
Use of either make_exception_ptr
or current_exception
is fine, depending on what exception you're trying to set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With