Log: use GetFullMessage() to print exceptions

Print all nested exceptions on a single line to avoid confusion.
This commit is contained in:
Max Kellermann 2019-05-22 18:24:45 +02:00
parent 749ad7cd83
commit e5f23678ca

View File

@ -19,8 +19,7 @@
#include "LogV.hxx" #include "LogV.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/Exception.hxx"
#include <exception>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -94,31 +93,13 @@ FormatError(const Domain &domain, const char *fmt, ...) noexcept
void void
LogError(const std::exception &e) noexcept LogError(const std::exception &e) noexcept
{ {
Log(exception_domain, LogLevel::ERROR, e.what()); LogError(exception_domain, GetFullMessage(e).c_str());
try {
std::rethrow_if_nested(e);
} catch (const std::exception &nested) {
LogError(nested, "nested");
} catch (...) {
Log(exception_domain, LogLevel::ERROR,
"Unrecognized nested exception");
}
} }
void void
LogError(const std::exception &e, const char *msg) noexcept LogError(const std::exception &e, const char *msg) noexcept
{ {
FormatError(exception_domain, "%s: %s", msg, e.what()); FormatError(exception_domain, "%s: %s", msg, GetFullMessage(e).c_str());
try {
std::rethrow_if_nested(e);
} catch (const std::exception &nested) {
LogError(nested);
} catch (...) {
Log(exception_domain, LogLevel::ERROR,
"Unrecognized nested exception");
}
} }
void void
@ -136,27 +117,14 @@ FormatError(const std::exception &e, const char *fmt, ...) noexcept
void void
LogError(const std::exception_ptr &ep) noexcept LogError(const std::exception_ptr &ep) noexcept
{ {
try { LogError(exception_domain, GetFullMessage(ep).c_str());
std::rethrow_exception(ep);
} catch (const std::exception &e) {
LogError(e);
} catch (...) {
Log(exception_domain, LogLevel::ERROR,
"Unrecognized exception");
}
} }
void void
LogError(const std::exception_ptr &ep, const char *msg) noexcept LogError(const std::exception_ptr &ep, const char *msg) noexcept
{ {
try { FormatError(exception_domain, "%s: %s", msg,
std::rethrow_exception(ep); GetFullMessage(ep).c_str());
} catch (const std::exception &e) {
LogError(e, msg);
} catch (...) {
FormatError(exception_domain,
"%s: Unrecognized exception", msg);
}
} }
void void