diff --git a/src/util/Exception.hxx b/src/util/Exception.hxx index 2a2729194..bbe7f2d4a 100644 --- a/src/util/Exception.hxx +++ b/src/util/Exception.hxx @@ -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 +inline std::exception_ptr +NestCurrentException(T &&t) noexcept +{ + try { + std::throw_with_nested(std::forward(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)); - } catch (...) { - return std::current_exception(); - } + return NestCurrentException(std::forward(t)); } }