🔨 small refactoring
The solution with a std::runtime_error member is more elegant. It allows to have std::exception as base class again. However, I still have no idea why GCC thinks the copy constructor may throw...
This commit is contained in:
parent
cc36c65a89
commit
c333679a96
2 changed files with 12 additions and 6 deletions
|
@ -123,13 +123,13 @@ Extension of std::exception objects with a member @a id for exception ids.
|
||||||
|
|
||||||
@since version 3.0.0
|
@since version 3.0.0
|
||||||
*/
|
*/
|
||||||
class exception : public std::runtime_error
|
class exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// returns the explanatory string
|
/// returns the explanatory string
|
||||||
virtual const char* what() const noexcept override
|
virtual const char* what() const noexcept override
|
||||||
{
|
{
|
||||||
return std::runtime_error::what();
|
return m.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the id of the exception
|
/// the id of the exception
|
||||||
|
@ -137,13 +137,16 @@ class exception : public std::runtime_error
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
exception(int id_, const char* what_arg)
|
exception(int id_, const char* what_arg)
|
||||||
: std::runtime_error(what_arg), id(id_)
|
: id(id_), m(what_arg)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static std::string name(const std::string& ename, int id_)
|
static std::string name(const std::string& ename, int id_)
|
||||||
{
|
{
|
||||||
return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
|
return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::runtime_error m;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -123,13 +123,13 @@ Extension of std::exception objects with a member @a id for exception ids.
|
||||||
|
|
||||||
@since version 3.0.0
|
@since version 3.0.0
|
||||||
*/
|
*/
|
||||||
class exception : public std::runtime_error
|
class exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// returns the explanatory string
|
/// returns the explanatory string
|
||||||
virtual const char* what() const noexcept override
|
virtual const char* what() const noexcept override
|
||||||
{
|
{
|
||||||
return std::runtime_error::what();
|
return m.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the id of the exception
|
/// the id of the exception
|
||||||
|
@ -137,13 +137,16 @@ class exception : public std::runtime_error
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
exception(int id_, const char* what_arg)
|
exception(int id_, const char* what_arg)
|
||||||
: std::runtime_error(what_arg), id(id_)
|
: id(id_), m(what_arg)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static std::string name(const std::string& ename, int id_)
|
static std::string name(const std::string& ename, int id_)
|
||||||
{
|
{
|
||||||
return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
|
return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::runtime_error m;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in a new issue