Commit 90de2c4b authored by Max Kellermann's avatar Max Kellermann

util/Exception: move code to NestCurrentException()

parent 9d63c822
...@@ -56,6 +56,21 @@ ThrowException(std::exception_ptr ep) ...@@ -56,6 +56,21 @@ ThrowException(std::exception_ptr ep)
} }
/** /**
* Create a nested exception, wrapping #ep inside the
* std::current_exception().
*/
template<typename T>
inline std::exception_ptr
NestCurrentException(T &&t) noexcept
{
try {
std::throw_with_nested(std::forward<T>(t));
} catch (...) {
return std::current_exception();
}
}
/**
* Create a nested exception, wrapping #ep inside (a copy of) #t. * Create a nested exception, wrapping #ep inside (a copy of) #t.
*/ */
template<typename T> template<typename T>
...@@ -65,11 +80,7 @@ NestException(std::exception_ptr ep, T &&t) noexcept ...@@ -65,11 +80,7 @@ NestException(std::exception_ptr ep, T &&t) noexcept
try { try {
std::rethrow_exception(ep); std::rethrow_exception(ep);
} catch (...) { } catch (...) {
try { return NestCurrentException(std::forward<T>(t));
std::throw_with_nested(std::forward<T>(t));
} catch (...) {
return std::current_exception();
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment