Commit ba09e22c authored by Max Kellermann's avatar Max Kellermann

util/Exception: add GetFullMessage(std::exception)

parent 6515b972
...@@ -30,13 +30,10 @@ ...@@ -30,13 +30,10 @@
#include "Exception.hxx" #include "Exception.hxx"
std::string std::string
GetFullMessage(std::exception_ptr ep, GetFullMessage(const std::exception &e,
const char *fallback, const char *separator) noexcept const char *fallback, const char *separator) noexcept
{ {
try { try {
std::rethrow_exception(ep);
} catch (const std::exception &e) {
try {
std::rethrow_if_nested(e); std::rethrow_if_nested(e);
return e.what(); return e.what();
} catch (...) { } catch (...) {
...@@ -44,6 +41,16 @@ GetFullMessage(std::exception_ptr ep, ...@@ -44,6 +41,16 @@ GetFullMessage(std::exception_ptr ep,
GetFullMessage(std::current_exception(), GetFullMessage(std::current_exception(),
fallback, separator); fallback, separator);
} }
}
std::string
GetFullMessage(std::exception_ptr ep,
const char *fallback, const char *separator) noexcept
{
try {
std::rethrow_exception(ep);
} catch (const std::exception &e) {
return GetFullMessage(e, fallback, separator);
} catch (const std::nested_exception &ne) { } catch (const std::nested_exception &ne) {
return GetFullMessage(ne.nested_ptr(), fallback, separator); return GetFullMessage(ne.nested_ptr(), fallback, separator);
} }
......
...@@ -34,6 +34,15 @@ ...@@ -34,6 +34,15 @@
#include <string> #include <string>
/** /**
* Obtain the full concatenated message of an exception and its nested
* chain.
*/
std::string
GetFullMessage(const std::exception &e,
const char *fallback="Unknown exception",
const char *separator="; ") noexcept;
/**
* Extract the full message of a C++ exception, considering its nested * Extract the full message of a C++ exception, considering its nested
* exceptions (if any). * exceptions (if any).
*/ */
......
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