33 #ifndef __H__UG__COMMON__ERROR__
34 #define __H__UG__COMMON__ERROR__
48 #define PRETTY_FUNCTION __PRETTY_FUNCTION__
50 #define PRETTY_FUNCTION __FUNCTION__
57 #define UG_THROW(msg) {ug_throw_error(); std::stringstream __ss; __ss << msg; \
58 throw(ug::UGError(__ss.str(),__FILE__,__LINE__));}
61 #define UG_COND_THROW(cond, msg) { if(cond) { UG_THROW(msg); } }
64 #define UG_CATCH_THROW(msg) catch(ug::UGError& err){std::stringstream __ss; __ss << msg;\
65 err.push_msg(__ss.str(),__FILE__,__LINE__); throw(err);} \
66 catch(const std::exception& ex) { std::stringstream __ss; __ss << msg;\
67 throw ug::UGError(__ss.str(), ex,__FILE__,__LINE__); }
69 #define UG_CATCH_PRINT(msg) \
70 catch (ug::UGError& err)\
72 std::stringstream __ss;\
74 err.push_msg(__ss.str(), __FILE__, __LINE__);\
75 UG_LOG(err.get_stacktrace());\
77 catch (const std::exception& ex)\
79 std::stringstream __ss;\
81 ug::UGError err(__ss.str(), ex, __FILE__, __LINE__);\
82 UG_LOG(err.get_stacktrace());\
85 #define UG_CATCH_THROW_FUNC() UG_CATCH_THROW(PRETTY_FUNCTION << "failed. ")
107 const char* file =
" -- no file -- ",
const unsigned long line = 0)
110 const char* file =
" -- no file -- ",
const unsigned long line = 0)
113 UGError(
const std::string &msg,
const std::exception &
ex,
const char *file,
const unsigned long line);
119 void push_msg(
const std::string& msg,
const char* file =
" -- no file -- ",
120 const unsigned long line = 0)
128 void push_msg(
const char* msg,
const char* file =
" -- no file -- ",
129 const unsigned long line = 0)
153 std::stringstream ss;
154 for(
size_t i = 0; i <
num_msg(); ++i)
181 #define THROW_IF_NOT_EQUAL(s1, s2) { UG_COND_THROW(s1 != s2, "mismatch: " << UG_TO_STRING(s1) << " = " << s1 << " != " << UG_TO_STRING(s2) << " = " << s2 << "."); }
182 #define THROW_IF_NOT_EQUAL_3(s1, s2, s3) { THROW_IF_NOT_EQUAL(s1, s2); THROW_IF_NOT_EQUAL(s1, s3); }
183 #define THROW_IF_NOT_EQUAL_4(s1, s2, s3, s4) { THROW_IF_NOT_EQUAL(s1, s2); THROW_IF_NOT_EQUAL(s1, s3); THROW_IF_NOT_EQUAL(s1, s4); }
185 #define ASSERT_EQUAL(s1, s2) { UG_COND_THROW(s1 != s2, "mismatch: " << UG_TO_STRING(s1) << " = " << s1 << " != " << UG_TO_STRING(s2) << " = " << s2 << "."); }
186 #define ASSERT_EQUAL_3(s1, s2, s3) { ASSERT_EQUAL(s1, s2); ASSERT_EQUAL(s1, s3); }
187 #define ASSERT_EQUAL_4(s1, s2, s3, s4) { ASSERT_EQUAL(s1, s2); ASSERT_EQUAL(s1, s3); ASSERT_EQUAL(s1, s4); }
This special error is used to perform a soft-abort e.g. during script execution.
Definition: error.h:173
SoftAbort(std::string msg)
Definition: error.h:175
Instances of this class or of derived classes are thrown if errors arise.
Definition: error.h:104
std::vector< unsigned long > m_vLine
Definition: error.h:164
void push_msg(const std::string &msg, const char *file=" -- no file -- ", const unsigned long line=0)
adds a message to the message stack
Definition: error.h:119
const std::string & get_msg(size_t i) const
returns a message in the message-stack (innermost is first)
Definition: error.h:143
void push_msg(const char *msg, const char *file=" -- no file -- ", const unsigned long line=0)
adds a message to the message stack
Definition: error.h:128
std::string get_stacktrace() const
Definition: error.h:151
const std::string & get_file(size_t i) const
returns the file where a message occured
Definition: error.h:146
virtual ~UGError()
virtual destructor
Definition: error.h:116
std::vector< std::string > m_vMsg
Definition: error.h:162
unsigned long get_line(size_t i) const
returns the line where a message occured
Definition: error.h:149
std::vector< std::string > m_vFile
Definition: error.h:163
const std::string & get_msg() const
returns the initial message
Definition: error.h:137
UGError(const std::string &msg, const char *file=" -- no file -- ", const unsigned long line=0)
Definition: error.h:109
UGError(const char *msg, const char *file=" -- no file -- ", const unsigned long line=0)
Definition: error.h:106
size_t num_msg() const
number of messages in message-stack
Definition: error.h:140
parameterString ex
Executes the specified script.
Definition: command_line_util.lua:350
void ug_throw_error()
called whenever UG_THROW or UG_THROW_REGISTRY_ERROR is called.
Definition: assert.cpp:164
std::string ErrorStringFromStdException(const std::exception *pex)
Definition: error.cpp:39