2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1997-2002
5
* Sleepycat Software. All rights reserved.
11
static const char revid[] = "$Id$";
18
#include "dbinc/cxx_int.h"
20
// tmpString is used to create strings on the stack
25
tmpString(const char *str1,
29
const char *str5 = 0);
30
~tmpString() { delete [] s_; }
31
operator const char *() { return (s_); }
37
tmpString::tmpString(const char *str1,
43
size_t len = strlen(str1);
66
// Note: would not be needed if we can inherit from exception
67
// It does not appear to be possible to inherit from exception
68
// with the current Microsoft library (VC5.0).
70
static char *dupString(const char *s)
72
char *r = new char[strlen(s)+1];
77
////////////////////////////////////////////////////////////////////////
81
////////////////////////////////////////////////////////////////////////
83
DbException::~DbException()
89
DbException::DbException(int err)
92
what_ = dupString(db_strerror(err));
95
DbException::DbException(const char *description)
98
what_ = dupString(tmpString(description));
101
DbException::DbException(const char *prefix, int err)
104
what_ = dupString(tmpString(prefix, ": ", db_strerror(err)));
107
DbException::DbException(const char *prefix1, const char *prefix2, int err)
110
what_ = dupString(tmpString(prefix1, ": ", prefix2, ": ",
114
DbException::DbException(const DbException &that)
117
what_ = dupString(that.what_);
120
DbException &DbException::operator = (const DbException &that)
126
what_ = 0; // in case new throws exception
127
what_ = dupString(that.what_);
132
int DbException::get_errno() const
137
const char *DbException::what() const
142
////////////////////////////////////////////////////////////////////////
144
// DbMemoryException //
146
////////////////////////////////////////////////////////////////////////
148
static const char *memory_err_desc = "Dbt not large enough for available data";
149
DbMemoryException::~DbMemoryException()
153
DbMemoryException::DbMemoryException(Dbt *dbt)
154
: DbException(memory_err_desc, ENOMEM)
159
DbMemoryException::DbMemoryException(const char *description)
160
: DbException(description, ENOMEM)
165
DbMemoryException::DbMemoryException(const char *prefix, Dbt *dbt)
166
: DbException(prefix, memory_err_desc, ENOMEM)
171
DbMemoryException::DbMemoryException(const char *prefix1, const char *prefix2,
173
: DbException(prefix1, prefix2, ENOMEM)
178
DbMemoryException::DbMemoryException(const DbMemoryException &that)
185
&DbMemoryException::operator =(const DbMemoryException &that)
188
DbException::operator=(that);
194
Dbt *DbMemoryException::get_dbt() const
199
////////////////////////////////////////////////////////////////////////
201
// DbDeadlockException //
203
////////////////////////////////////////////////////////////////////////
205
DbDeadlockException::~DbDeadlockException()
209
DbDeadlockException::DbDeadlockException(const char *description)
210
: DbException(description, DB_LOCK_DEADLOCK)
214
DbDeadlockException::DbDeadlockException(const DbDeadlockException &that)
220
&DbDeadlockException::operator =(const DbDeadlockException &that)
223
DbException::operator=(that);
227
////////////////////////////////////////////////////////////////////////
229
// DbLockNotGrantedException //
231
////////////////////////////////////////////////////////////////////////
233
DbLockNotGrantedException::~DbLockNotGrantedException()
238
DbLockNotGrantedException::DbLockNotGrantedException(const char *prefix,
239
db_lockop_t op, db_lockmode_t mode, const Dbt *obj, const DbLock lock,
241
: DbException(prefix, DbEnv::strerror(DB_LOCK_NOTGRANTED),
248
lock_ = new DbLock(lock);
251
DbLockNotGrantedException::DbLockNotGrantedException
252
(const DbLockNotGrantedException &that)
258
lock_ = new DbLock(*that.lock_);
259
index_ = that.index_;
262
DbLockNotGrantedException
263
&DbLockNotGrantedException::operator =(const DbLockNotGrantedException &that)
266
DbException::operator=(that);
270
lock_ = new DbLock(*that.lock_);
271
index_ = that.index_;
276
db_lockop_t DbLockNotGrantedException::get_op() const
281
db_lockmode_t DbLockNotGrantedException::get_mode() const
286
const Dbt* DbLockNotGrantedException::get_obj() const
291
DbLock* DbLockNotGrantedException::get_lock() const
296
int DbLockNotGrantedException::get_index() const
303
////////////////////////////////////////////////////////////////////////
305
// DbRunRecoveryException //
307
////////////////////////////////////////////////////////////////////////
309
DbRunRecoveryException::~DbRunRecoveryException()
313
DbRunRecoveryException::DbRunRecoveryException(const char *description)
314
: DbException(description, DB_RUNRECOVERY)
318
DbRunRecoveryException::DbRunRecoveryException
319
(const DbRunRecoveryException &that)
324
DbRunRecoveryException
325
&DbRunRecoveryException::operator =(const DbRunRecoveryException &that)
328
DbException::operator=(that);