summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-20 14:52:54 +0200
committerMax Kellermann <max@musicpd.org>2018-08-20 14:52:54 +0200
commit90de2c4bd622360489e5273f9384e6ab67a1caf3 (patch)
treec830f46085d58a6acc4c1420c784983baeb9ed9a
parent9d63c8220bc01693691618cd507f8d57434bfac0 (diff)
util/Exception: move code to NestCurrentException()
-rw-r--r--src/util/Exception.hxx21
1 files 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
@@ -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.
*/
template<typename 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));
}
}