13 #ifndef PROJECT_EXCEPTION_H
14 #define PROJECT_EXCEPTION_H
20 #include "tdf_error_codes.h"
25 using namespace std::string_literals;
29 #define GET_MACRO(_1,_2,NAME,...) NAME
30 #define ThrowException(...) EXPAND(EXPAND(GET_MACRO(__VA_ARGS__, ThrowExceptionCode, ThrowExceptionNoCode))(__VA_ARGS__))
31 #define ThrowExceptionNoCode(message) virtru::_ThrowVirtruException(message, __SOURCE_FILENAME__, __LINE__)
32 #define ThrowExceptionCode(message, code) virtru::_ThrowVirtruException(message, __SOURCE_FILENAME__, __LINE__, code)
37 explicit Exception(
const std::string &what,
int code = VIRTRU_GENERAL_ERROR) :
38 std::runtime_error{
"[Error code: "s + std::to_string(code) +
"] " + what},
41 int code() const noexcept {
54 inline void _ThrowVirtruException(std::string &&errorStringPrefix,
const char *fileName,
unsigned int lineNumber,
int code = VIRTRU_GENERAL_ERROR) {
55 std::ostringstream os;
56 os <<
" [" << fileName <<
":" << lineNumber <<
"] ";
59 if(IsLogLevelDebug() || IsLogLevelTrace()){
60 throw Exception { os.str() + move (errorStringPrefix), code};
63 throw Exception { move (errorStringPrefix), code};
70 #endif //PROJECT_EXCEPTION_H
int code() const noexcept
Definition: tdf_exception.h:41
Definition: tdf_exception.h:35
int m_code
Definition: tdf_exception.h:46
Exception(const std::string &what, int code=VIRTRU_GENERAL_ERROR)
Definition: tdf_exception.h:37
void _ThrowVirtruException(std::string &&errorStringPrefix, const char *fileName, unsigned int lineNumber, int code=VIRTRU_GENERAL_ERROR)
Definition: tdf_exception.h:54