util/Exception: add GetFullMessage(std::exception)
This commit is contained in:
@@ -29,6 +29,20 @@
|
|||||||
|
|
||||||
#include "Exception.hxx"
|
#include "Exception.hxx"
|
||||||
|
|
||||||
|
std::string
|
||||||
|
GetFullMessage(const std::exception &e,
|
||||||
|
const char *fallback, const char *separator) noexcept
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
std::rethrow_if_nested(e);
|
||||||
|
return e.what();
|
||||||
|
} catch (...) {
|
||||||
|
return std::string(e.what()) + separator +
|
||||||
|
GetFullMessage(std::current_exception(),
|
||||||
|
fallback, separator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
GetFullMessage(std::exception_ptr ep,
|
GetFullMessage(std::exception_ptr ep,
|
||||||
const char *fallback, const char *separator) noexcept
|
const char *fallback, const char *separator) noexcept
|
||||||
@@ -36,14 +50,7 @@ GetFullMessage(std::exception_ptr ep,
|
|||||||
try {
|
try {
|
||||||
std::rethrow_exception(ep);
|
std::rethrow_exception(ep);
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
try {
|
return GetFullMessage(e, fallback, separator);
|
||||||
std::rethrow_if_nested(e);
|
|
||||||
return e.what();
|
|
||||||
} catch (...) {
|
|
||||||
return std::string(e.what()) + separator +
|
|
||||||
GetFullMessage(std::current_exception(),
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,15 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#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).
|
||||||
|
Reference in New Issue
Block a user