Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

d_Error.h

Go to the documentation of this file.
00001 
00002 #ifndef d_Error_h
00003 #define d_Error_h 1
00004 //------------------------------------------------------------------------------
00005 
00006 #include "d_Errorcodes.h"
00007 #include "cODMGLiteral.h"
00008 
00009 #include "cpp_exception.h"
00010 
00011 #include "d_String.h"
00012 //------------------------------------------------------------------------------
00013 
00014 /**
00015  * Orient ODBMS exceptions and errors.
00016  *
00017  * Orient exceptions are treated by raising d_Error objects.
00018  *
00019  * For this reason each database operation (object management, queries, etc.)
00020  * had to be included inside a C++ try-catch block. This means that there is no
00021  * need to check the result at every database operation, but rather exception
00022  * raised in a try block will be handled in the catch block (full C++
00023  * integration).
00024  * 
00025  * It inherits from C++ exception class.
00026  *
00027  * LOCATION:
00028  * d_Error.h
00029  *
00030  * USAGE:
00031  * try
00032  * {
00033  *   ...
00034  * }
00035  * catch( d_Error* <err-object> )
00036  * {
00037  *   ...
00038  * }
00039  * 
00040  * Where:
00041  * 
00042  * <ERR-OBJECT>:                NAME OF D_ERROR OBJECT CAUGHT.
00043  *
00044  * EXAMPLES:
00045  * try
00046  * {
00047  *   ...
00048  *   db.open( "business" );
00049  *   ...
00050  * }
00051  * catch( d_Error* err )
00052  * {
00053  *    * CATCH DATABASE ERRORS
00054  *   cerr << "Database error :";
00055  * 
00056  *    * SWITCHING ERROR KIND
00057  *   switch( err->get_kind() )
00058  *   {
00059  *     case d_Error::d_Error_DatabaseOpen:
00060  *       cerr << "Database not open";
00061  *       break;
00062  *
00063  *     default:
00064  *       cerr << "Generic";
00065  *   }
00066  *   delete err;
00067  * }
00068  *
00069  * ODMG:
00070  * Compliant 
00071 */
00072 
00073 class _ODLL d_Error : public cpp_exception
00074 {
00075   public:
00076     typedef d_Long kind;
00077 
00078     /**
00079      * Default Constructor.
00080      *
00081      * ODMG    :        Compliant 
00082      */
00083     d_Error ();
00084 
00085     /**
00086      * Create a d_Error object specifying error kind.
00087      *
00088      * Create a d_Error object with error kind equal to <iKind>.
00089      *
00090      * ODMG    :        Compliant 
00091      */
00092     d_Error (kind iKind);
00093 
00094     /**
00095      * Copy Constructor.
00096      *
00097      * ODMG    :        Compliant 
00098      */
00099     d_Error (const d_Error& iSource);
00100 
00101     /**
00102      * Destructor.
00103      *
00104      * ODMG    :        Compliant 
00105      */
00106     ~d_Error();
00107 
00108     /**
00109      * Returns a message that describes the error.
00110      *
00111      * ODMG    :        Compliant 
00112      */
00113     virtual const char * what () const throw();
00114 
00115     /**
00116      * Returns error's kind.
00117      *
00118      * ODMG    :        Compliant 
00119      */
00120     kind get_kind ();
00121 
00122     /**
00123      * Set error's kind.
00124      *
00125      * ODMG    :        Compliant 
00126      */
00127     void set_kind (kind iKind);
00128 
00129     /**
00130      * Get the Detail error if any, otherwise null.
00131      *
00132      * ODMG    :        Extension
00133      */
00134     d_Error* get_detail();
00135 
00136     /**
00137      * Set the Detail error.
00138      *
00139      * ODMG    :        Extension
00140      */
00141     void set_detail( d_Error* iDetail );
00142 
00143     /**
00144      * Check if contains the kind requested in the current object and
00145      * in the detail objects.
00146      *
00147      * ODMG    :        Extension
00148      */
00149     bool contains( kind iKind );
00150 
00151     /**
00152      * Append a string to the error message.
00153      *
00154      * ODMG    :        Compliant 
00155      */
00156     d_Error& operator << (const d_String& iInfo);
00157 
00158     /**
00159      * Append a integer to the error message.
00160      *
00161      * ODMG    :        Compliant
00162      */
00163     d_Error& operator << (d_ULong iInfo);
00164 
00165     /**
00166      * Append a c-string to the error message.
00167      *
00168      * ODMG    :        Compliant 
00169      */
00170     d_Error& operator << (const char* iInfo);
00171 
00172     /**
00173      * Append the message of another d_Error object.
00174      *
00175      * ODMG    :        Compliant 
00176      */
00177     d_Error& operator << (const d_Error& iInfo);
00178 
00179   private:
00180     // Internal.
00181     char* findDescription (const kind iKind);
00182 
00183     // Internal.
00184     d_Error* detail;
00185 
00186     // Internal.
00187     kind curr_kind;
00188     // Internal.
00189     d_String message;
00190 };
00191 
00192 //------------------------------------------------------------------------------
00193 // ERROR FACILITIES :
00194 
00195 //#define OERROR_DEBUG  1
00196 
00197 #define OERROR(inKind,extra)      {d_Error* _tmperr = new d_Error(inKind); \
00198                                    *_tmperr << extra; \
00199                                    throw(_tmperr);}
00200 #define OERRORD(inKind,detail,extra) {d_Error* _tmperr = new d_Error(inKind); \
00201                                       *_tmperr << extra; \
00202                                       _tmperr->set_detail(detail); \
00203                                       throw(_tmperr);}
00204 
00205 //------------------------------------------------------------------------------
00206 //------------------------------------------------------------------------------
00207 
00208 #endif
00209 

Generated on Fri Nov 29 17:12:13 2002 for Orient ODBMS Just Edition v. 2.0e by doxygen1.3-rc1