2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
2016-12-29 14:28:03 +01:00
|
|
|
|
|
|
|
#include "Exception.hxx"
|
|
|
|
|
2020-02-01 13:13:08 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2017-07-05 17:04:32 +02:00
|
|
|
template<typename T>
|
|
|
|
static void
|
|
|
|
AppendNestedMessage(std::string &result, T &&e,
|
|
|
|
const char *fallback, const char *separator) noexcept
|
2017-07-05 17:02:21 +02:00
|
|
|
{
|
|
|
|
try {
|
2017-07-05 17:04:32 +02:00
|
|
|
std::rethrow_if_nested(std::forward<T>(e));
|
|
|
|
} catch (const std::exception &nested) {
|
|
|
|
result += separator;
|
|
|
|
result += nested.what();
|
|
|
|
AppendNestedMessage(result, nested, fallback, separator);
|
|
|
|
} catch (const std::nested_exception &ne) {
|
|
|
|
AppendNestedMessage(result, ne, fallback, separator);
|
2019-08-21 12:19:03 +02:00
|
|
|
} catch (const char *s) {
|
|
|
|
result += separator;
|
|
|
|
result += s;
|
2017-07-05 17:02:21 +02:00
|
|
|
} catch (...) {
|
2017-07-05 17:04:32 +02:00
|
|
|
result += separator;
|
|
|
|
result += fallback;
|
2017-07-05 17:02:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 17:04:32 +02:00
|
|
|
std::string
|
|
|
|
GetFullMessage(const std::exception &e,
|
|
|
|
const char *fallback, const char *separator) noexcept
|
|
|
|
{
|
|
|
|
std::string result = e.what();
|
|
|
|
AppendNestedMessage(result, e, fallback, separator);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-29 14:28:03 +01:00
|
|
|
std::string
|
2017-07-05 16:59:40 +02:00
|
|
|
GetFullMessage(std::exception_ptr ep,
|
|
|
|
const char *fallback, const char *separator) noexcept
|
2016-12-29 14:28:03 +01:00
|
|
|
{
|
|
|
|
try {
|
2020-02-01 13:13:08 +01:00
|
|
|
std::rethrow_exception(std::move(ep));
|
2016-12-29 14:28:03 +01:00
|
|
|
} catch (const std::exception &e) {
|
2017-07-05 17:02:21 +02:00
|
|
|
return GetFullMessage(e, fallback, separator);
|
2017-07-05 17:01:43 +02:00
|
|
|
} catch (const std::nested_exception &ne) {
|
|
|
|
return GetFullMessage(ne.nested_ptr(), fallback, separator);
|
2019-08-21 12:19:03 +02:00
|
|
|
} catch (const char *s) {
|
|
|
|
return s;
|
2017-07-05 17:04:32 +02:00
|
|
|
} catch (...) {
|
|
|
|
return fallback;
|
2016-12-29 14:28:03 +01:00
|
|
|
}
|
|
|
|
}
|