1 #ifndef _EXCEPTION_H_INCLUDED_ 2 #define _EXCEPTION_H_INCLUDED_ 3 /////////////////////////////////////////////////////////////////////////////// 4 // 5 // Exception.h 6 // ----------- 7 // Exception class definition 8 // 9 // Design and Implementation by Bjoern Lemke 10 // 11 // (C)opyright 2000-2016 Bjoern Lemke 12 // 13 // INTERFACE MODULE 14 // 15 // Class: Exception 16 // 17 // Description: Exception manager class 18 // 19 // Status: CLEAN 20 // 21 /////////////////////////////////////////////////////////////////////////////// 22 23 #include <stdio.h> 24 25 // BASE INCLUDES 26 #include "StackT.h" 27 #include "Chain.h" 28 29 #define EXLOC Chain(__FILE__), __LINE__ 30 31 class Exception { 32 33 public: 34 Exception(const Chain & module,int line,const Chain & msg)35 Exception(const Chain& module, int line, const Chain& msg) 36 { 37 ExcepStruct ms; 38 ms._msg = msg; 39 ms._line = line; 40 ms._module = module; 41 _excepStack.Push(ms); 42 43 _baseMsg = msg; 44 } 45 Exception(const Chain & module,int line,const Chain & msg,Exception e)46 Exception(const Chain& module, int line, const Chain& msg, Exception e) 47 { 48 _excepStack = e._excepStack; 49 50 ExcepStruct es; 51 es._msg = msg; 52 es._line = line; 53 es._module = module; 54 55 _excepStack.Push(es); 56 57 _baseMsg = e._baseMsg; 58 } ~Exception()59 ~Exception() 60 { 61 _excepStack.Empty(); 62 } 63 pop(Chain & module,int & line,Chain & msg)64 bool pop(Chain& module, int& line, Chain& msg) 65 { 66 67 ExcepStruct es; 68 if ( _excepStack.Pop(es) ) 69 { 70 module = es._module; 71 line = es._line; 72 msg = es._msg; 73 return true; 74 } 75 else 76 { 77 return false; 78 } 79 80 } 81 pop(Chain & msg)82 bool pop(Chain& msg) 83 { 84 85 ExcepStruct es; 86 if ( _excepStack.Pop(es) ) 87 { 88 msg = es._msg; 89 return true; 90 } 91 else 92 { 93 return false; 94 } 95 } 96 print()97 void print() 98 { 99 ExcepStruct es; 100 while (_excepStack.Pop(es) ) 101 { 102 cout << es._module << " ( Line " << es._line << " ) : " << es._msg << endl; 103 } 104 } 105 106 Exception& operator = (const Exception& e) 107 { 108 _excepStack = e._excepStack; 109 _baseMsg = e._baseMsg; 110 return (*this); 111 } 112 getBaseMsg()113 const Chain& getBaseMsg() 114 { 115 return _baseMsg; 116 } 117 118 private: 119 120 class ExcepStruct { 121 public: 122 ExcepStruct()123 ExcepStruct() {}; ~ExcepStruct()124 ~ExcepStruct() {}; 125 ExcepStruct& operator = (const ExcepStruct& es) { 126 _msg = es._msg; 127 _module = es._module; 128 _line = es._line; 129 return (*this); 130 } 131 Chain _msg; 132 Chain _module; 133 int _line; 134 135 }; 136 StackT<ExcepStruct> _excepStack; 137 138 Chain _baseMsg; 139 }; 140 #endif 141