00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #include <string.h>
00013 #include <errno.h>
00014
00015 #include "db_cxx.h"
00016 #include "dbinc/cxx_int.h"
00017
00018
00019
00020
00021
00022 static char *dupString(const char *s)
00023 {
00024 char *r = new char[strlen(s)+1];
00025 strcpy(r, s);
00026 return (r);
00027 }
00028
00030
00031
00032
00034
00035 DbException::~DbException() throw()
00036 {
00037 delete [] what_;
00038 }
00039
00040 DbException::DbException(int err)
00041 : err_(err)
00042 , env_(0)
00043 {
00044 describe(0, 0);
00045 }
00046
00047 DbException::DbException(const char *description)
00048 : err_(0)
00049 , env_(0)
00050 {
00051 describe(0, description);
00052 }
00053
00054 DbException::DbException(const char *description, int err)
00055 : err_(err)
00056 , env_(0)
00057 {
00058 describe(0, description);
00059 }
00060
00061 DbException::DbException(const char *prefix, const char *description, int err)
00062 : err_(err)
00063 , env_(0)
00064 {
00065 describe(prefix, description);
00066 }
00067
00068 DbException::DbException(const DbException &that)
00069 : __DB_STD(exception)()
00070 , what_(dupString(that.what_))
00071 , err_(that.err_)
00072 , env_(0)
00073 {
00074 }
00075
00076 DbException &DbException::operator = (const DbException &that)
00077 {
00078 if (this != &that) {
00079 err_ = that.err_;
00080 delete [] what_;
00081 what_ = dupString(that.what_);
00082 }
00083 return (*this);
00084 }
00085
00086 void DbException::describe(const char *prefix, const char *description)
00087 {
00088 char msgbuf[1024], *p, *end;
00089
00090 p = msgbuf;
00091 end = msgbuf + sizeof(msgbuf) - 1;
00092
00093 if (prefix != NULL) {
00094 strncpy(p, prefix, (p < end) ? end - p: 0);
00095 p += strlen(prefix);
00096 strncpy(p, ": ", (p < end) ? end - p: 0);
00097 p += 2;
00098 }
00099 if (description != NULL) {
00100 strncpy(p, description, (p < end) ? end - p: 0);
00101 p += strlen(description);
00102 if (err_ != 0) {
00103 strncpy(p, ": ", (p < end) ? end - p: 0);
00104 p += 2;
00105 }
00106 }
00107 if (err_ != 0) {
00108 strncpy(p, db_strerror(err_), (p < end) ? end - p: 0);
00109 p += strlen(db_strerror(err_));
00110 }
00111
00112
00113
00114
00115
00116 if (p >= end)
00117 *end = '\0';
00118
00119 what_ = dupString(msgbuf);
00120 }
00121
00122 int DbException::get_errno() const
00123 {
00124 return (err_);
00125 }
00126
00127 const char *DbException::what() const throw()
00128 {
00129 return (what_);
00130 }
00131
00132 DbEnv *DbException::get_env() const
00133 {
00134 return env_;
00135 }
00136
00137 void DbException::set_env(DbEnv *env)
00138 {
00139 env_= env;
00140 }
00141
00143
00144
00145
00147
00148 static const char *memory_err_desc = "Dbt not large enough for available data";
00149 DbMemoryException::~DbMemoryException() throw()
00150 {
00151 }
00152
00153 DbMemoryException::DbMemoryException(Dbt *dbt)
00154 : DbException(memory_err_desc, ENOMEM)
00155 , dbt_(dbt)
00156 {
00157 }
00158
00159 DbMemoryException::DbMemoryException(const char *prefix, Dbt *dbt)
00160 : DbException(prefix, memory_err_desc, ENOMEM)
00161 , dbt_(dbt)
00162 {
00163 }
00164
00165 DbMemoryException::DbMemoryException(const DbMemoryException &that)
00166 : DbException(that)
00167 , dbt_(that.dbt_)
00168 {
00169 }
00170
00171 DbMemoryException
00172 &DbMemoryException::operator =(const DbMemoryException &that)
00173 {
00174 if (this != &that) {
00175 DbException::operator=(that);
00176 dbt_ = that.dbt_;
00177 }
00178 return (*this);
00179 }
00180
00181 Dbt *DbMemoryException::get_dbt() const
00182 {
00183 return (dbt_);
00184 }
00185
00187
00188
00189
00191
00192 DbDeadlockException::~DbDeadlockException() throw()
00193 {
00194 }
00195
00196 DbDeadlockException::DbDeadlockException(const char *description)
00197 : DbException(description, DB_LOCK_DEADLOCK)
00198 {
00199 }
00200
00201 DbDeadlockException::DbDeadlockException(const DbDeadlockException &that)
00202 : DbException(that)
00203 {
00204 }
00205
00206 DbDeadlockException
00207 &DbDeadlockException::operator =(const DbDeadlockException &that)
00208 {
00209 if (this != &that)
00210 DbException::operator=(that);
00211 return (*this);
00212 }
00213
00215
00216
00217
00219
00220 DbLockNotGrantedException::~DbLockNotGrantedException() throw()
00221 {
00222 delete lock_;
00223 }
00224
00225 DbLockNotGrantedException::DbLockNotGrantedException(const char *prefix,
00226 db_lockop_t op, db_lockmode_t mode, const Dbt *obj, const DbLock lock,
00227 int index)
00228 : DbException(prefix, DbEnv::strerror(DB_LOCK_NOTGRANTED),
00229 DB_LOCK_NOTGRANTED)
00230 , op_(op)
00231 , mode_(mode)
00232 , obj_(obj)
00233 , lock_(new DbLock(lock))
00234 , index_(index)
00235 {
00236 }
00237
00238 DbLockNotGrantedException::DbLockNotGrantedException(const char *description)
00239 : DbException(description, DB_LOCK_NOTGRANTED)
00240 , op_(DB_LOCK_GET)
00241 , mode_(DB_LOCK_NG)
00242 , obj_(NULL)
00243 , lock_(NULL)
00244 , index_(0)
00245 {
00246 }
00247
00248 DbLockNotGrantedException::DbLockNotGrantedException
00249 (const DbLockNotGrantedException &that)
00250 : DbException(that)
00251 {
00252 op_ = that.op_;
00253 mode_ = that.mode_;
00254 obj_ = that.obj_;
00255 lock_ = (that.lock_ != NULL) ? new DbLock(*that.lock_) : NULL;
00256 index_ = that.index_;
00257 }
00258
00259 DbLockNotGrantedException
00260 &DbLockNotGrantedException::operator =(const DbLockNotGrantedException &that)
00261 {
00262 if (this != &that) {
00263 DbException::operator=(that);
00264 op_ = that.op_;
00265 mode_ = that.mode_;
00266 obj_ = that.obj_;
00267 lock_ = (that.lock_ != NULL) ? new DbLock(*that.lock_) : NULL;
00268 index_ = that.index_;
00269 }
00270 return (*this);
00271 }
00272
00273 db_lockop_t DbLockNotGrantedException::get_op() const
00274 {
00275 return op_;
00276 }
00277
00278 db_lockmode_t DbLockNotGrantedException::get_mode() const
00279 {
00280 return mode_;
00281 }
00282
00283 const Dbt* DbLockNotGrantedException::get_obj() const
00284 {
00285 return obj_;
00286 }
00287
00288 DbLock* DbLockNotGrantedException::get_lock() const
00289 {
00290 return lock_;
00291 }
00292
00293 int DbLockNotGrantedException::get_index() const
00294 {
00295 return index_;
00296 }
00297
00299
00300
00301
00303
00304 DbRepHandleDeadException::~DbRepHandleDeadException() throw()
00305 {
00306 }
00307
00308 DbRepHandleDeadException::DbRepHandleDeadException(const char *description)
00309 : DbException(description, DB_REP_HANDLE_DEAD)
00310 {
00311 }
00312
00313 DbRepHandleDeadException::DbRepHandleDeadException
00314 (const DbRepHandleDeadException &that)
00315 : DbException(that)
00316 {
00317 }
00318
00319 DbRepHandleDeadException
00320 &DbRepHandleDeadException::operator =(const DbRepHandleDeadException &that)
00321 {
00322 if (this != &that)
00323 DbException::operator=(that);
00324 return (*this);
00325 }
00326
00328
00329
00330
00332
00333 DbRunRecoveryException::~DbRunRecoveryException() throw()
00334 {
00335 }
00336
00337 DbRunRecoveryException::DbRunRecoveryException(const char *description)
00338 : DbException(description, DB_RUNRECOVERY)
00339 {
00340 }
00341
00342 DbRunRecoveryException::DbRunRecoveryException
00343 (const DbRunRecoveryException &that)
00344 : DbException(that)
00345 {
00346 }
00347
00348 DbRunRecoveryException
00349 &DbRunRecoveryException::operator =(const DbRunRecoveryException &that)
00350 {
00351 if (this != &that)
00352 DbException::operator=(that);
00353 return (*this);
00354 }