From 90de2c4bd622360489e5273f9384e6ab67a1caf3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Aug 2018 14:52:54 +0200 Subject: [PATCH] util/Exception: move code to NestCurrentException() --- src/util/Exception.hxx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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)); } }