00001
00025 #ifndef __MAGIC_MEXCEPTION_H__
00026 #define __MAGIC_MEXCEPTION_H__
00027
00028 #include "magic/mobject.h"
00029
00030 namespace MagiC {
00031 class String;
00032 }
00033
00034 BEGIN_NAMESPACE (MagiC);
00035
00037
00038
00039
00040
00041
00042
00043
00045
00047
00048
00062 class Exception : public Object {
00063 String* mWhat;
00064 public:
00065
00072 Exception (const String& what);
00073 Exception (const Exception& orig);
00074 ~Exception ();
00075
00078 const String& what () const {return *mWhat;}
00079 };
00080
00081 #define EXCEPTIONCLASS(eclass) \
00082 class eclass : public Exception {\
00083 public:\
00084 eclass (const String& what_arg) : Exception (what_arg) { }\
00085 virtual ~eclass () {;}\
00086 };
00087
00088
00089
00092 EXCEPTIONCLASS (generic_exception);
00093 EXCEPTIONCLASS (invalid_format);
00094 EXCEPTIONCLASS (assertion_failed);
00095 EXCEPTIONCLASS (forwarded_failure);
00096 EXCEPTIONCLASS (file_not_found);
00097 EXCEPTIONCLASS (system_failure);
00098 EXCEPTIONCLASS (open_failure);
00099 EXCEPTIONCLASS (invalid_flags);
00100 EXCEPTIONCLASS (file_not_open);
00101 EXCEPTIONCLASS (device_not_open);
00102 EXCEPTIONCLASS (stream_failure);
00103 EXCEPTIONCLASS (end_of_stream);
00104 EXCEPTIONCLASS (check_failed);
00105 EXCEPTIONCLASS (out_of_bounds);
00106 EXCEPTIONCLASS (out_of_range);
00107 EXCEPTIONCLASS (runtime_error);
00108 EXCEPTIONCLASS (io_error);
00113
00114 EXCEPTIONCLASS (must_overload);
00115 #define MUST_OVERLOAD {assertwith (__FILE__, __LINE__, __FUNCTION__, "MUST_OVERLOAD", format("%%ERR: Method of baseclass must be overloaded by descendant %s", typeid(*this).name()));}
00116
00117 EXCEPTIONCLASS (forbidden_call);
00118 #define FORBIDDEN {throw forbidden_call (format("%%ERR: Forbidden execution at %s[%d]: %s()", __FILE__, __LINE__, __FUNCTION__));}
00119
00120 EXCEPTIONCLASS (not_implemented);
00121 #define NOT_IMPLEMENTED {throw not_implemented (format("%%ERR: Function not implemented at %s[%d]: %s()", __FILE__, __LINE__, __FUNCTION__));}
00122
00126 #define failtrace_begin try {
00127 #define failtrace_end \
00128 } catch (Exception e) { \
00129 throw forwarded_failure (format ("%s\n%%ERR: Exception forwaded at %s[%d]:%s()", \
00130 (CONSTR) e.what(), __FILE__, __LINE__, __FUNCTION__)); \
00131 }
00132
00133 #define FUNCTION_BEGIN failtrace_begin
00134 #define FUNCTION_END failtrace_end
00135
00139 #define failtrace(expr) failtrace_begin; expr; failtrace_end;
00140
00141 #define FAILTRACE failtrace
00142
00147 #define trywith(expr,err) \
00148 try { \
00149 expr; \
00150 } catch (Exception e) { \
00151 throw forwarded_failure (format ("%s\n%%ERR: Exception forwaded at %s[%d]:%s()\n%%ERR: %s", \
00152 (CONSTR) e.what(), __FILE__, __LINE__, __FUNCTION__, (CONSTR) err)); \
00153 }
00154
00155 #define TRYWITH trywith
00156
00166 enum assertmodes {ASSERT_THROW=0, ASSERT_CRASH=1, ASSERT_EXIT=2, ASSERT_DONTCARE=3};
00167
00168 extern FILE* dbgout;
00169
00170 extern int assertmode;
00171
00173 extern void assertwith (const char* filename, int lineno, const char* funcname,
00174 const char* condition=NULL, const char* message=NULL);
00175
00176 END_NAMESPACE;
00177
00178 #endif
00179