Commit 553365b9 authored by Max Kellermann's avatar Max Kellermann

Log: add std::exception_ptr overloads

parent 100308db
...@@ -136,6 +136,48 @@ FormatError(const std::exception &e, const char *fmt, ...) ...@@ -136,6 +136,48 @@ FormatError(const std::exception &e, const char *fmt, ...)
} }
void 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) LogError(const Error &error)
{ {
Log(error.GetDomain(), LogLevel::ERROR, error.GetMessage()); Log(error.GetDomain(), LogLevel::ERROR, error.GetMessage());
......
...@@ -23,9 +23,7 @@ ...@@ -23,9 +23,7 @@
#include "LogLevel.hxx" #include "LogLevel.hxx"
#include "Compiler.h" #include "Compiler.h"
namespace std { #include <exception>
class exception;
}
class Error; class Error;
class Domain; class Domain;
...@@ -93,6 +91,16 @@ gcc_printf(2,3) ...@@ -93,6 +91,16 @@ gcc_printf(2,3)
void void
FormatError(const std::exception &e, const char *fmt, ...); 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) gcc_printf(2,3)
void void
FormatError(const Domain &domain, const char *fmt, ...); FormatError(const Domain &domain, const char *fmt, ...);
......
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