Commit 1098d271 authored by Max Kellermann's avatar Max Kellermann

util/Error: add bridge to std::exception

parent 51168169
......@@ -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)
{
......
......@@ -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;
......
......@@ -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) {
......
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