51 RES_ERR_BAD_ALLOCATION,
54 RES_ERR_NOT_IMPLEMENTED,
58 inline const char *getErrorMessage(
const RES_T &res)
63 case RES_ERR_BAD_ALLOCATION:
64 return "Bad allocation";
66 return "Unknown error";
76 Error() noexcept(
true) : line(0)
80 Error(
const string &descr) noexcept(
true) : description(cleanDescr(descr))
85 Error(
const string &descr,
const char *func,
const char *_file,
86 const int _line,
const char *expr) noexcept(
true)
87 : description(cleanDescr(descr)),
function(func), file(_file),
88 line(_line), expression(expr)
93 Error(
const string &descr,
const char *func,
const char *_file,
94 const int _line) noexcept(
true)
95 : description(cleanDescr(descr)),
function(func), file(_file),
101 Error(
const char *func,
const char *_file,
const int _line,
102 const char *expr) noexcept(
true)
103 :
function(func), file(_file), line(_line), expression(expr)
108 Error(
const string &descr,
const char *func,
109 const char *expr) noexcept(
true)
110 : description(cleanDescr(descr)),
function(func), expression(expr)
115 Error(
const char *func,
const char *expr) noexcept(
true)
116 :
function(func), expression(expr)
121 virtual ~
Error() noexcept(
true)
125 virtual const char *what()
const noexcept(
true)
127 return this->message.c_str();
132 cout <<
"Error:" << this->what() << endl;
138 if (!
function.empty())
139 buf <<
"\n in function: " <<
function;
140 if (!description.empty())
141 buf <<
"\n error: " << description;
143 if (!expression.empty()) {
144 if (description.empty())
145 buf <<
"\n error: assert " << expression;
147 buf <<
" ( assert " << expression <<
" )";
150 buf <<
"\n file: " << file <<
":" << line;
152 this->message = buf.str();
156 inline string cleanDescr(
const string descr)
161 return descr.substr(1, descr.length() - 2);
167 #if defined NDEBUG && defined __clang__
175 #define ASSERT_1_ARG(func, file, line, expr) \
177 Error(func, file, line, #expr).show(); \
180 #define ASSERT_2_ARGS(func, file, line, expr, errCode) \
182 Error(#errCode, func, file, line, #expr).show(); \
185 #define ASSERT_3_ARGS(func, file, line, expr, errCode, retVal) \
187 Error(#errCode, func, file, line, #expr).show(); \
191 #define ERR_MSG(msg) Error(msg, __FUNC__, __FILE__, __LINE__).show()
193 #define ASSERT_NARGS_CHOOSER(...) \
194 GET_4TH_ARG(__VA_ARGS__, ASSERT_3_ARGS, ASSERT_2_ARGS, ASSERT_1_ARG, ...)
197 #define ASSERT(...) \
198 EXPAND(ASSERT_NARGS_CHOOSER(__VA_ARGS__)(__FUNC__, __FILE__, __LINE__, \
201 #define ASSERT(...) \
202 ASSERT_NARGS_CHOOSER(__VA_ARGS__)(__FUNC__, __FILE__, __LINE__, __VA_ARGS__)