diff --git a/src/Log.cxx b/src/Log.cxx index 65d3be824..fd3a3c106 100644 --- a/src/Log.cxx +++ b/src/Log.cxx @@ -29,9 +29,6 @@ #include #include -/** Domain for std::exception */ -static constexpr Domain exception_domain("exception"); - void LogFormatV(const Domain &domain, LogLevel level, const char *fmt, va_list ap) { diff --git a/src/util/Error.cxx b/src/util/Error.cxx index 67a1b03fd..d6f4c1595 100644 --- a/src/util/Error.cxx +++ b/src/util/Error.cxx @@ -31,6 +31,9 @@ #include "Error.hxx" #include "Domain.hxx" +#include +#include + #ifdef WIN32 #include #endif @@ -40,6 +43,8 @@ #include #include +const Domain exception_domain("exception"); + const Domain errno_domain("errno"); #ifdef WIN32 @@ -48,6 +53,26 @@ const Domain win32_domain("win32"); Error::~Error() {} +void +Error::Set(const std::exception &src) +{ + try { + /* classify the exception */ + throw src; + } catch (const std::system_error &se) { + if (se.code().category() == std::system_category()) { +#ifdef WIN32 + Set(win32_domain, se.code().value(), se.what()); +#else + Set(errno_domain, se.code().value(), se.what()); +#endif + } else + Set(exception_domain, src.what()); + } catch (...) { + Set(exception_domain, src.what()); + } +} + void Error::Set(const Domain &_domain, int _code, const char *_message) { diff --git a/src/util/Error.hxx b/src/util/Error.hxx index ab66ae5cb..b86cb3918 100644 --- a/src/util/Error.hxx +++ b/src/util/Error.hxx @@ -40,6 +40,13 @@ class Domain; +namespace std { + class exception; +} + +/** Domain for std::exception */ +extern const Domain exception_domain; + extern const Domain errno_domain; #ifdef WIN32 @@ -126,6 +133,8 @@ public: message = other.message; } + void Set(const std::exception &src); + void Set(const Domain &_domain, int _code, const char *_message); void Set(const Domain &_domain, const char *_message) {