Log: add std::exception_ptr overloads

This commit is contained in:
Max Kellermann 2016-09-09 19:09:40 +02:00
parent 100308db02
commit 553365b942
2 changed files with 53 additions and 3 deletions

View File

@ -135,6 +135,48 @@ FormatError(const std::exception &e, const char *fmt, ...)
LogError(e, msg);
}
void
LogError(const std::exception_ptr &ep)
{
try {
std::rethrow_exception(ep);
} catch (const std::exception &e) {
LogError(e);
} catch (const Error &e) {
LogError(e);
} catch (...) {
Log(exception_domain, LogLevel::ERROR,
"Unrecognized exception");
}
}
void
LogError(const std::exception_ptr &ep, const char *msg)
{
try {
std::rethrow_exception(ep);
} catch (const std::exception &e) {
LogError(e, msg);
} catch (const Error &e) {
LogError(e, msg);
} catch (...) {
FormatError(exception_domain,
"%s: Unrecognized exception", msg);
}
}
void
FormatError(const std::exception_ptr &ep, const char *fmt, ...)
{
char msg[1024];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
LogError(ep, msg);
}
void
LogError(const Error &error)
{

View File

@ -23,9 +23,7 @@
#include "LogLevel.hxx"
#include "Compiler.h"
namespace std {
class exception;
}
#include <exception>
class Error;
class Domain;
@ -93,6 +91,16 @@ gcc_printf(2,3)
void
FormatError(const std::exception &e, const char *fmt, ...);
void
LogError(const std::exception_ptr &ep);
void
LogError(const std::exception_ptr &ep, const char *msg);
gcc_printf(2,3)
void
FormatError(const std::exception_ptr &ep, const char *fmt, ...);
gcc_printf(2,3)
void
FormatError(const Domain &domain, const char *fmt, ...);