Main Page   Class Hierarchy   Compound List   File List   Compound Members  

exception.h

00001 #ifndef CMA_EXCEPTION_DEFINED
00002 #define CMA_EXCEPTION_DEFINED
00003 
00004 #include <stdlib.h>
00005 #include <assert.h>
00006 #include <string>
00007 
00008 namespace CMa
00009 {
00015         class Exception
00016         {
00017         public:
00018                 virtual void getDescription(string& descr)=0;
00019         };
00020 
00059         class Error : public Exception
00060         {
00061         public:
00062                 enum Code
00063                 {
00064                         //Stack errors
00065                         STACK_OVERFLOW,
00066                         STACK_UNDERFLOW,
00067                         //Aritmethical errors
00068                         DIVISION_BY_ZERO,
00069                         MODULUS_IS_ZERO,
00070                         //Memory access errors
00071                         READ_FROM_NULL_POINTER,
00072                         WRITE_TO_NULL_POINTER,
00073                         READ_FROM_STACK_FRAME,
00074                         WRITE_TO_STACK_FRAME,                   
00075                         WRONG_HEAP_ADDRESS,
00076                         WRONG_HEAP_INTERVALL,
00077                         //Code errors
00078                         WRONG_CODE_ADDRESS,
00079                         WRONG_JUMP_ADDRESS,
00080                         WRONG_CALL_ADDRESS,
00081                         WRONG_OP_CODE,
00082                         WRONG_OP_ARGUMENT,
00083                         WRONG_OP_ARGUMENT_ADDRESS,                      
00084                         //Frame making errors
00085                         CALL_UNDERFLOW,
00086                         CORRUPTED_FRAME,
00087                         
00088                         OTHER
00089                 };
00090 
00091                 Error(Code code)
00092                 {
00093                         this->code = code;
00094                 }
00095 
00096                 Error(char* descr)
00097                 {
00098                         this->code = OTHER;
00099                         this->descr = descr;
00100                 }
00101 
00102 
00103                 void getDescription(string& descr)
00104                 {
00105                         switch (code)
00106                         {
00107                             //Stack errors
00108                                 case STACK_OVERFLOW:
00109                                         descr = "Stack overflow";                               
00110                                     break;
00111                                 case STACK_UNDERFLOW:
00112                                         descr = "Stack underflow";                              
00113                                     break;                      
00114                             //Aritmethical errors
00115                                 case DIVISION_BY_ZERO:
00116                     descr = "Division by zero";
00117                                     break;                              
00118                                 case MODULUS_IS_ZERO:
00119                                     descr = "Modulus is zero";
00120                                     break;                              
00121                             //Memory access errors
00122                                 case READ_FROM_NULL_POINTER:
00123                                     descr = "Attempt to read from NULL-pointer";
00124                                     break;                              
00125                                 case WRITE_TO_NULL_POINTER:
00126                                     descr = "Attempt to write to NULL-pointer";
00127                                     break;                              
00128                                 case READ_FROM_STACK_FRAME:
00129                                     descr = "Unauthorized attempt to read data from stack frame";
00130                                     break;                              
00131                                 case WRITE_TO_STACK_FRAME:
00132                                     descr = "Unauthorised attempt to write data to stack frame";                        
00133                                     break;                              
00134                                 case WRONG_HEAP_ADDRESS:
00135                                     descr = "Stack/heap address is invalid";
00136                                     break;                              
00137                                 case WRONG_HEAP_INTERVALL:
00138                                     descr = "Stack/heap interval is invalid";
00139                                     break;                              
00140                             //Code errors
00141                                 case WRONG_CODE_ADDRESS:
00142                                     descr = "Instruction address is invalid";
00143                     break;
00144                                 case WRONG_JUMP_ADDRESS:
00145                                     descr = "Jump address is invalid";
00146                                     break;                              
00147                                 case WRONG_CALL_ADDRESS:
00148                                     descr = "Function call to invalid address";
00149                                     break;                              
00150                                 case WRONG_OP_CODE:
00151                                         descr = "Wrong operation code";                         
00152                                     break;                              
00153                                 case WRONG_OP_ARGUMENT:
00154                                         descr = "Wrong operation argument";                             
00155                                     break;                              
00156                                 case WRONG_OP_ARGUMENT_ADDRESS:
00157                                     descr = "Address of instruction argument is invalid";               
00158                                     break;                                      
00159                             //Frame making errors
00160                                 case CALL_UNDERFLOW:
00161                                     descr = "Error in CALL less arguments than needed";
00162                                     break;                              
00163                                 case CORRUPTED_FRAME:
00164                                     descr = "Unable to jump back stack frame is corrupted";
00165                                     break;                              
00166                 //Other errors
00167                                 case OTHER:
00168                                         descr = this->descr;
00169                     break;
00170 
00171                                 default:
00172                                         descr = "Unknown error";
00173                         }
00174                 }
00175 
00176         protected:
00177                 Code code;
00178                 string descr;
00179         };
00180 
00186         class Failure : public Exception
00187         {
00188         public:
00189                 Failure(char* descr)
00190                 {
00191                         this->descr = descr;
00192                 }
00193 
00194                 virtual void getDescription(string& descr)
00195                 {
00196                         descr = this->descr;
00197                 }
00198 
00199         protected:
00200                 string descr;
00201         };
00202 }
00203 
00204 #endif
00205 

Generated on Tue Oct 12 03:30:43 1999 by doxygen1.2.18