util/Error: add bridge to std::exception
This commit is contained in:
parent
51168169e7
commit
1098d271b8
@ -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
|
||||
@ -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)
|
||||
{
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user