Commit d9e8ce22 authored by Max Kellermann's avatar Max Kellermann

util/Error: use std::exception_ptr instead of std::exception

Necessary to preserve type information. The try/catch sequence didn't work previously. Same fix as in commit 1c904000
parent c85ba733
......@@ -222,7 +222,7 @@ try {
return true;
} catch (const std::exception &e) {
error.Set(e);
error.Set(std::current_exception());
return false;
}
......
......@@ -81,7 +81,7 @@ try {
std::move(reader), info.GetSize(),
mutex, cond);
} catch (const std::exception &e) {
error.Set(e);
error.Set(std::current_exception());
return nullptr;
}
......@@ -102,7 +102,7 @@ try {
offset = new_offset;
return true;
} catch (const std::exception &e) {
error.Set(e);
error.Set(std::current_exception());
return false;
}
......@@ -113,7 +113,7 @@ try {
offset += nbytes;
return nbytes;
} catch (const std::exception &e) {
error.Set(e);
error.Set(std::current_exception());
return 0;
}
......
......@@ -31,7 +31,6 @@
#include "Error.hxx"
#include "Domain.hxx"
#include <exception>
#include <system_error>
#ifdef WIN32
......@@ -54,11 +53,11 @@ const Domain win32_domain("win32");
Error::~Error() {}
void
Error::Set(const std::exception &src)
Error::Set(std::exception_ptr src)
{
try {
/* classify the exception */
throw src;
std::rethrow_exception(src);
} catch (const std::system_error &se) {
if (se.code().category() == std::system_category()) {
#ifdef WIN32
......@@ -67,9 +66,11 @@ Error::Set(const std::exception &src)
Set(errno_domain, se.code().value(), se.what());
#endif
} else
Set(exception_domain, src.what());
Set(exception_domain, se.what());
} catch (const std::exception &e) {
Set(exception_domain, e.what());
} catch (...) {
Set(exception_domain, src.what());
Set(exception_domain, "Unknown exception");
}
}
......
......@@ -35,15 +35,12 @@
#include <string>
#include <utility>
#include <exception>
#include <assert.h>
class Domain;
namespace std {
class exception;
}
/** Domain for std::exception */
extern const Domain exception_domain;
......@@ -133,7 +130,7 @@ public:
message = other.message;
}
void Set(const std::exception &src);
void Set(std::exception_ptr src);
void Set(const Domain &_domain, int _code, 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