Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

Exception.h

00001 #ifndef _RDA_EXCEPTION_H_
00002 #define _RDA_EXCEPTION_H_
00003 //
00004 // 21 Mar 2001, N.Trofimov
00005 // 10 Jul 2002 NNT
00006 //    - added exception to stream
00007 // 13 Jul 2006, W.Gajewski
00008 //    - string management adjusted
00009 // 14 Feb 2007 WPG
00010 //    - rdaNoPermission added to support RBAC exceptions
00011 // 17 Jun 2007 WPG
00012 //    - rdaAccessDenied, rdaBadToken and rdaTokenExpired exceptions added to support RBAC-related exceptions
00013 //
00014 // TODO: doc for <<
00015 //
00016 #include <string>
00017 
00018 class rdaData;
00019 
00020 //
00021 // Helper macro for the rdaInternalError constructor
00022 //
00023 #define __HERE__ __FILE__, __LINE__
00024 // not very safe: maybe RDA_ERROR_HERE ?
00025 
00045 class rdaInternalError
00046 {
00047    
00048    char* message;
00049    char* file;
00050    int line;
00051    
00052    public:
00053   
00054       rdaInternalError(const char* f, int l, const char* msg = "");
00055       virtual ~rdaInternalError();
00056 
00057       rdaInternalError(const rdaInternalError& ex);
00058       rdaInternalError& operator=(const rdaInternalError& ex);
00059 
00063       const char* getMessage() const { return message; }
00067       const char* getFile() const { return file; }
00073       int getLine() const { return line; }   
00074 };
00075 
00082 class rdaException
00083 {   
00084    protected:
00085    
00086       char* message;
00087    
00088    public:
00089 
00090       rdaException(const char* msg = "");
00091     
00092       rdaException(const rdaException& ex);
00093 
00094       rdaException& operator=(const rdaException& ex);
00095 
00096       virtual ~rdaException();
00097 
00101       virtual const char* getType() const
00102       {
00103          return "rdaException";
00104       }
00105    
00109       const char* getMessage() const
00110       {
00111          return message;
00112       }
00113 };
00114 
00120 class rdaBadParameter : public rdaException
00121 {
00122    public:
00123    
00127       rdaBadParameter() {}
00131       rdaBadParameter(const char* msg) : rdaException(msg) {}
00132 
00133       virtual const char* getType() const
00134       {
00135          return "rdaBadParameter";
00136       }
00137 };
00138 
00147 class rdaTypeMismatch : public rdaException
00148 {
00149    public:
00150 
00151       rdaTypeMismatch() {}
00152       rdaTypeMismatch(const char* msg) : rdaException(msg) { }
00153 
00154       virtual const char* getType() const
00155       {
00156          return "rdaTypeMismatch";
00157       }
00158 };
00159 
00173 class rdaTimeOut : public rdaException
00174 {
00175    public:
00176 
00177       rdaTimeOut() {}
00178       rdaTimeOut(const char* msg) : rdaException(msg) { }
00179 
00180       virtual const char* getType() const
00181       {
00182          return "rdaTimeOut";
00183       }
00184 };
00185 
00186 
00192 class rdaNoConnection : public rdaException
00193 {
00194    public:
00195 
00196       rdaNoConnection() {}
00197       rdaNoConnection(const char* msg) : rdaException(msg) { }
00198 
00199       virtual const char* getType() const
00200       {
00201          return "rdaNoConnection";
00202       }
00203 };
00204 
00205 class rdaNoPermission : public rdaException
00206 {
00207 public:
00208    rdaNoPermission(const char* msg) : rdaException(msg) { }
00209 
00210    virtual const char* getType() const
00211    {
00212       return "rdaNoPermission";
00213    }
00214 
00215 };
00216 
00227 class rdaInternalException : public rdaException
00228 {
00229    public:
00230 
00231       rdaInternalException() {}
00232       rdaInternalException(const char* msg) : rdaException(msg) { }
00233 
00234       virtual const char* getType() const
00235       {
00236          return "rdaInternalException";
00237       }
00238 };
00239 
00244 class rdaAccessDenied : public rdaNoPermission
00245 {
00246 public:
00247 
00248    rdaAccessDenied( const char* msg ) : rdaNoPermission( msg ), type( 0 )
00249    {
00250    }
00251 
00252    rdaAccessDenied( long type_, const char* msg ) : rdaNoPermission( msg ), type( type_ )
00253    {
00254    }
00255 
00256    virtual const char* getType() const
00257    {
00258       return "rdaAccessDenied";
00259    }
00260 
00261    virtual long getErrorType() const
00262    {
00263       return type;
00264    }
00265 private:
00266    long type;
00267 };
00268 
00273 class rdaBadToken : public rdaNoPermission
00274 {
00275 public:
00276 
00277    rdaBadToken( const char* msg ) : rdaNoPermission( msg ), type( 0 )
00278    {
00279    }
00280 
00281    rdaBadToken( long type_, const char* msg ) : rdaNoPermission( msg ), type( type_ )
00282    {
00283    }
00284 
00285    virtual const char* getType() const
00286    {
00287       return "rdaBadToken";
00288    }
00289 
00290    virtual long getErrorType() const
00291    {
00292       return type;
00293    }
00294 private:
00295    long type;
00296 };
00297 
00302 class rdaTokenExpired : public rdaNoPermission
00303 {
00304 public:
00305 
00306    rdaTokenExpired( const char* msg ) : rdaNoPermission( msg ), type( 0 )
00307    {
00308    }
00309 
00310    rdaTokenExpired( long type_, const char* msg ) : rdaNoPermission( msg ), type( type_ )
00311    {
00312    }
00313 
00314    virtual const char* getType() const
00315    {
00316       return "rdaTokenExpired";
00317    }
00318 
00319    virtual long getErrorType() const
00320    {
00321       return type;
00322    }
00323 private:
00324    long type;
00325 };
00326 
00349 class rdaIOError : public rdaException
00350 {
00351    char* category;
00352    long errCode;
00353    rdaData* details;
00354    
00355    public:
00356 
00360       rdaIOError(const char* errorCategory, 
00361                  long errorCode, 
00362                  const char* errorMessage);
00363 
00367       rdaIOError(const char* errorCategory, 
00368                  long errorCode, 
00369                  const char* errorMessage, 
00370                  const rdaData& errorDetails);
00371 
00372       rdaIOError(const rdaIOError& ex);
00373       rdaIOError& operator=(const rdaIOError& ex);
00374       
00375       virtual ~rdaIOError();
00376   
00380       const char* getCategory() const
00381       {
00382          return category;
00383       }
00387       long getCode() const
00388       {
00389          return errCode;
00390       }      
00395       const rdaData* getDetails() const
00396       {
00397          return details;
00398       }       
00399       
00400       virtual const char* getType() const
00401       {
00402          return "rdaIOError";
00403       }
00404 };
00405 
00406 #ifndef RDA_HAS_NO_IOSTREAM
00407    #ifndef RDA_HAS_NO_STD_IOSTREAM
00408       #include <iostream>
00409       using std::ostream;
00410       using std::endl;
00411    #else
00412       #include <iostream.h>
00413    #endif
00414 
00417 ostream& operator<<(ostream& os, const rdaException& ex);
00421 ostream& operator<<(ostream& os, const rdaInternalError& ex);
00422 #endif
00423 
00424 #endif
00425  

RDA-2.3 documentation - 27 Jun 2007 - N.Trofimov