00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 using namespace MagiC;
00034
00036
00037
00051 class Exception : public Object {
00052 String* mWhat;
00053 public:
00054
00061 Exception (const String& what);
00062 Exception (const Exception& orig);
00063 ~Exception ();
00064
00067 const String& what () const {return *mWhat;}
00068 };
00069
00070 #define EXCEPTIONCLASS(eclass) \
00071 class eclass : public Exception {\
00072 public:\
00073 eclass (const String& what_arg) : Exception (what_arg) { }\
00074 virtual ~eclass () {;}\
00075 };
00076
00077
00078
00079 EXCEPTIONCLASS (generic_exception);
00080 EXCEPTIONCLASS (invalid_format);
00081 EXCEPTIONCLASS (assertion_failed);
00082 EXCEPTIONCLASS (forwarded_failure);
00083 EXCEPTIONCLASS (file_not_found);
00084 EXCEPTIONCLASS (check_failed);
00085 EXCEPTIONCLASS (out_of_bounds);
00086 EXCEPTIONCLASS (out_of_range);
00087 EXCEPTIONCLASS (runtime_error);
00088
00092 #define failtrace(expr) try {expr;} catch (Exception e) {throw forwarded_failure (format ("%s\n%%ERR: Exception forwaded at %s[%d]:%s()", (CONSTR) e.what(), __FILE__, __LINE__, __FUNCTION__));}
00093 #define FAILTRACE failtrace
00094
00099 #define trywith(expr,err) try {expr;} catch (Exception e) {throw forwarded_failure (format ("%s\n%%ERR: Exception forwaded at %s[%d]:%s()\n%%ERR: %s", (CONSTR) e.what(), __FILE__, __LINE__, __FUNCTION__, (CONSTR) err));}
00100 #define TRYWITH trywith
00101
00102
00103 #endif