Added automagic constructor inheritance.
This commit is contained in:
parent
3ac76f1fac
commit
3f0486b889
@ -23,6 +23,29 @@ typedef std::unordered_map<unsigned int, const char*> ErrorCodeMap;
|
||||
template<class ErrorType>
|
||||
class ErrorBase : public std::exception {
|
||||
public:
|
||||
ErrorBase(
|
||||
const unsigned int code,
|
||||
unsigned int line=0,
|
||||
std::string filename=""
|
||||
) noexcept : ErrorBase(
|
||||
code,
|
||||
ErrorBase<ErrorType>::lookup(code),
|
||||
line,
|
||||
filename
|
||||
) {}
|
||||
ErrorBase(
|
||||
const unsigned int code,
|
||||
const std::exception& trace,
|
||||
unsigned int line=0,
|
||||
std::string filename=""
|
||||
) noexcept : ErrorBase(
|
||||
code,
|
||||
ErrorBase<ErrorType>::lookup(code),
|
||||
trace,
|
||||
line,
|
||||
filename
|
||||
) {}
|
||||
|
||||
static std::string lookup(unsigned int);
|
||||
unsigned int code() const noexcept {
|
||||
return static_cast<const ErrorType*>(this)->_code;
|
||||
@ -71,29 +94,6 @@ protected:
|
||||
}
|
||||
_msg += "\n Trace: " + what_msg;
|
||||
}
|
||||
ErrorBase(
|
||||
const unsigned int code,
|
||||
unsigned int line=0,
|
||||
std::string filename=""
|
||||
) noexcept : ErrorBase(
|
||||
code,
|
||||
ErrorBase<ErrorType>::lookup(code),
|
||||
line,
|
||||
filename
|
||||
) {}
|
||||
|
||||
ErrorBase(
|
||||
const unsigned int code,
|
||||
const std::exception& trace,
|
||||
unsigned int line=0,
|
||||
std::string filename=""
|
||||
) noexcept : ErrorBase(
|
||||
code,
|
||||
ErrorBase<ErrorType>::lookup(code),
|
||||
trace,
|
||||
line,
|
||||
filename
|
||||
) {}
|
||||
|
||||
unsigned int _code;
|
||||
std::string _msg;
|
||||
@ -105,9 +105,10 @@ public:
|
||||
GENERAL, UNDEFINED, BADERRORCODE
|
||||
};
|
||||
|
||||
Error(unsigned int code) : ErrorBase<Error>(code, ErrorBase<Error>::lookup(code)) {}
|
||||
Error(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||
: ErrorBase<Error>(code, ErrorBase<Error>::lookup(code), trace, line, filename) {}
|
||||
using ErrorBase<Error>::ErrorBase;
|
||||
//Error(unsigned int code) : ErrorBase<Error>(code, ErrorBase<Error>::lookup(code)) {}
|
||||
//Error(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||
// : ErrorBase<Error>(code, ErrorBase<Error>::lookup(code), trace, line, filename) {}
|
||||
|
||||
friend ErrorBase<Error>;
|
||||
|
||||
|
||||
@ -7,11 +7,13 @@ using namespace nb;
|
||||
|
||||
class TestError : public ErrorBase<TestError> {
|
||||
public:
|
||||
TestError(unsigned int code, unsigned int line=0, const std::string& filename="")
|
||||
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code)) {}
|
||||
TestError(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code), trace, line, filename) {}
|
||||
//TestError(unsigned int code, unsigned int line=0, const std::string& filename="")
|
||||
// : ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code)) {}
|
||||
//TestError(unsigned int code, const std::exception& trace, unsigned int line=0, const std::string& filename="")
|
||||
// : ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code), trace, line, filename) {}
|
||||
|
||||
using ErrorBase<TestError>::ErrorBase;
|
||||
|
||||
enum ErrorCodes : unsigned int {
|
||||
A, B, C, D
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user