diff options
author | Max Kellermann <max@duempel.org> | 2015-12-18 00:24:43 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-12-18 00:24:43 +0100 |
commit | 1098d271b8e8207ce901267716c3335e90bfe585 (patch) | |
tree | a5da344d3ad2c1304f6dffa3b6ec29e815856004 /src | |
parent | 51168169e73528d388b39b826afe1df3370bd10a (diff) |
util/Error: add bridge to std::exception
Diffstat (limited to 'src')
-rw-r--r-- | src/Log.cxx | 3 | ||||
-rw-r--r-- | src/util/Error.cxx | 25 | ||||
-rw-r--r-- | src/util/Error.hxx | 9 |
3 files changed, 34 insertions, 3 deletions
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 <string.h> #include <errno.h> -/** 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 <exception> +#include <system_error> + #ifdef WIN32 #include <windows.h> #endif @@ -40,6 +43,8 @@ #include <stdio.h> #include <string.h> +const Domain exception_domain("exception"); + const Domain errno_domain("errno"); #ifdef WIN32 @@ -49,6 +54,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) { domain = &_domain; 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) { |