Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

Exception.H

Go to the documentation of this file.
00001 
00015 #ifndef EXCEPTION_H
00016 #define EXCEPTION_H
00017 #include <strstream>
00018 #include <string>
00019 
00020 using namespace std;
00021 
00022 namespace xchen
00023 {
00024   class Error 
00025   {
00026   public:
00027       typedef enum ErrOp { MEM_EXHAUST = 1, BAD_VALUE, UNDER_FLOW, OVER_FLOW };
00028 
00029       Error(ErrOp e) : error(e) { }
00030       string ErrorMessage() const;
00031       ErrOp error;
00032   };
00033 
00034   class ArrayError : public Error 
00035   {
00036       int idx;
00037   public:
00038       ArrayError(enum ErrOp e, int i) : Error(e), idx(i) { }
00039       string ErrorMessage() const { strstream s; s << "Index: " <<  idx << " " <<  ends; return s.str() + Error::ErrorMessage(); }
00040   };
00041 
00042 
00043   inline string Error :: ErrorMessage() const 
00044   {
00045     switch(error) 
00046     {
00047       case MEM_EXHAUST : return "memory exhaused"; 
00048       case BAD_VALUE   : return "bad value";
00049       case UNDER_FLOW  : return "array index under flow";
00050       case OVER_FLOW   : return "array index over flow";
00051     }
00052     return "";
00053   }
00054  
00055 }
00056 
00057 #endif

Generated on Wed Apr 7 21:40:49 2004 by doxygen1.2.18