util/Exception: move code to NestCurrentException()

This commit is contained in:
Max Kellermann 2018-08-20 14:52:54 +02:00
parent 9d63c8220b
commit 90de2c4bd6

View File

@ -55,6 +55,21 @@ ThrowException(std::exception_ptr ep)
std::rethrow_exception(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.
*/
@ -65,11 +80,7 @@ NestException(std::exception_ptr ep, T &&t) noexcept
try {
std::rethrow_exception(ep);
} catch (...) {
try {
std::throw_with_nested(std::forward<T>(t));
} catch (...) {
return std::current_exception();
}
return NestCurrentException(std::forward<T>(t));
}
}