9 #ifndef __libutilxx__sella__Exception_H__
10 #define __libutilxx__sella__Exception_H__
12 #include "../common.h"
26 #define NO_EXCEPTIONS throw ()
34 #define THROWS(e, ...) throw (e, ##__VA_ARGS__)
36 #define THROW(exception, format, ...) throw exception(false, __func__, __FILE__, __LINE__, 0, format, ##__VA_ARGS__)
37 #define THROW_CODE(exception, code, format, ...) throw exception(false, __func__, __FILE__, __LINE__, code, format, ##__VA_ARGS__)
38 #define THROW2(exception, format, ...) throw exception(true, __func__, __FILE__, __LINE__, 0, format, ##__VA_ARGS__)
39 #define THROW2_CODE(exception, code, format, ...) throw exception(true, __func__, __FILE__, __LINE__, code, format, ##__VA_ARGS__)
40 #define RETHROW(exception, e) throw exception(false, __func__, __FILE__, __LINE__, e.getCode(), e.what())
41 #define RETHROW_CODE(exception, code, e) throw exception(false, __func__, __FILE__, __LINE__, code, e.what())
42 #define RETHROW2(exception, e, format, ...) throw exception(false, __func__, __FILE__, __LINE__, 0, e, format, ##__VA_ARGS__)
43 #define RETHROW2_CODE(exception, code, e, format, ...) throw exception(false, __func__, __FILE__, __LINE__, code, e, format, ##__VA_ARGS__)
45 #define EXCEPTION_BUILDMESSAGE_CODE \
48 va_start(list, format); \
49 buildMessage(sysmsg, format, list); \
54 #define BUILD_EXCEPTION(T) \
55 class T : public sella::Exception { \
57 T(bool sysmsg, const char *function, const char *file, int line, int code, const char *format, ...) throw () : \
58 Exception(function, file, line, code) { EXCEPTION_BUILDMESSAGE_CODE }; \
59 T(bool sysmsg, const char *function, const char *file, int line, int code, sella::Exception &e, const char *format, ...) throw () : \
60 Exception(function, file, line, code) { EXCEPTION_BUILDMESSAGE_CODE; message.append(" Error: ").append(e.getMessage()); }; \
61 virtual const char* what() const throw () { return Exception::what(); } \
62 virtual int getCode() const throw () { return Exception::getCode(); } \
63 virtual const std::string getName() const throw () { return demangle(typeid(T).name()); } \
72 Exception(
const char *
function,
const char *file,
int line,
int code)
throw ();
73 Exception(
bool sysmsg,
const char *
function,
const char *file,
int line,
int code,
const char *format, ...)
throw ();
89 virtual const std::string& getFunction()
const throw ();
90 virtual const std::string& getFile()
const throw ();
91 virtual int getLine()
const throw ();
92 virtual int getCode()
const throw ();
93 virtual const std::string& getMessage()
const throw ();
94 virtual const char* what()
const throw ();
95 virtual const std::string& getStackTrace()
const throw ();
96 virtual const std::string getName()
const throw ();
98 virtual const std::string& str()
const throw ();
99 virtual const char* c_str()
const throw ();
101 static void enableStackTrace(
bool on =
true)
throw ();
104 std::string
function;
110 mutable std::string cache;
112 void buildMessage(
bool sysmsg,
const char *format, va_list list)
throw ();
113 const std::string demangle(
const char *name)
const throw ();