File indexing completed on 2024-05-18 08:29:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _DB_STL_EXCEPTION_H
0010 #define _DB_STL_EXCEPTION_H
0011
0012 #include <cstring>
0013 #include <cstdlib>
0014 #include <cstdio>
0015
0016 #include <iostream>
0017 #include <exception>
0018
0019 #include "dbstl_common.h"
0020
0021 START_NS(dbstl)
0022
0023 using std::cerr;
0024
0025
0026 void _exported throw_bdb_exception(const char *caller, int err_ret);
0027 #define COPY_CONSTRUCTOR(type) type(const type& t) : DbstlException(t){}
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 class _exported DbstlException : public DbException
0065 {
0066 public:
0067 explicit DbstlException(const char *msg) : DbException(msg) {}
0068 DbstlException(const char *msg, int err) : DbException(msg, err) {}
0069 DbstlException(const DbstlException&ex) : DbException(ex) {}
0070 explicit DbstlException(int err) : DbException(err) {}
0071 DbstlException(const char *prefix, const char *msg, int err) :
0072 DbException(prefix, msg, err) {}
0073
0074 const DbstlException& operator=(const DbstlException&exobj)
0075 {
0076 ASSIGNMENT_PREDCOND(exobj)
0077 DbException::operator =
0078 (dynamic_cast<const DbException&>(exobj));
0079 return exobj;
0080 }
0081
0082 virtual ~DbstlException() throw(){}
0083 };
0084
0085
0086 class _exported NotEnoughMemoryException : public DbstlException
0087 {
0088 size_t failed_size;
0089 public:
0090 NotEnoughMemoryException(const char *msg, size_t sz)
0091 : DbstlException(msg)
0092 {
0093 failed_size = sz;
0094 }
0095
0096
0097 NotEnoughMemoryException(const NotEnoughMemoryException &ex)
0098 : DbstlException(ex)
0099 {
0100 this->failed_size = ex.failed_size;
0101 }
0102 };
0103
0104
0105 class _exported InvalidIteratorException : public DbstlException
0106 {
0107 public:
0108 InvalidIteratorException() : DbstlException("Invalid Iterator")
0109 {
0110 }
0111
0112 explicit InvalidIteratorException(int error_code) :
0113 DbstlException("Invalid Iterator", error_code)
0114 {
0115 }
0116 COPY_CONSTRUCTOR(InvalidIteratorException)
0117 };
0118
0119
0120 class _exported InvalidCursorException : public DbstlException
0121 {
0122 public:
0123 InvalidCursorException() : DbstlException("Invalid cursor")
0124 {
0125 }
0126
0127 explicit InvalidCursorException(int error_code) :
0128 DbstlException("Invalid cursor", error_code)
0129 {
0130 }
0131 COPY_CONSTRUCTOR(InvalidCursorException)
0132 };
0133
0134
0135
0136 class _exported InvalidDbtException : public DbstlException
0137 {
0138 public:
0139 InvalidDbtException() : DbstlException("Invalid Dbt object")
0140 {
0141 }
0142
0143 explicit InvalidDbtException(int error_code) :
0144 DbstlException("Invalid Dbt object", error_code)
0145 {
0146 }
0147 COPY_CONSTRUCTOR(InvalidDbtException)
0148 };
0149
0150
0151
0152 class _exported FailedAssertionException : public DbstlException
0153 {
0154 private:
0155 char *err_msg_;
0156 public:
0157 virtual const char *what() const throw()
0158 {
0159 return err_msg_;
0160 }
0161
0162 FailedAssertionException(const char *fname, size_t lineno,
0163 const char *msg) : DbstlException(0)
0164 {
0165 u_int32_t sz;
0166 char *str;
0167
0168 str = (char *)DbstlMalloc(sz = (u_int32_t)(strlen(msg) +
0169 strlen(fname) + 128));
0170 _snprintf(str, sz,
0171 "In file %s at line %u, %s expression failed",
0172 fname, (unsigned int)lineno, msg);
0173 err_msg_ = str;
0174 #ifdef DEBUG
0175 fprintf(stderr, "%s", str);
0176 #endif
0177 }
0178
0179 FailedAssertionException(const FailedAssertionException&ex) :
0180 DbstlException(ex)
0181 {
0182 err_msg_ = (char *)DbstlMalloc((u_int32_t)
0183 strlen(ex.err_msg_) + 1);
0184 strcpy(err_msg_, ex.err_msg_);
0185 }
0186 virtual ~FailedAssertionException() throw()
0187 {
0188 free(err_msg_);
0189 }
0190 };
0191
0192
0193
0194
0195 class _exported NoSuchKeyException : public DbstlException
0196 {
0197 public:
0198 NoSuchKeyException()
0199 : DbstlException("\nNo such key in the container.")
0200 {
0201 }
0202
0203 COPY_CONSTRUCTOR(NoSuchKeyException)
0204 };
0205
0206
0207 class _exported InvalidArgumentException : public DbstlException
0208 {
0209 public:
0210 explicit InvalidArgumentException(const char *errmsg) :
0211 DbstlException(errmsg)
0212 {
0213 #ifdef DEBUG
0214 cerr<<errmsg;
0215 #endif
0216 }
0217
0218 InvalidArgumentException(const char *argtype, const char *arg) :
0219 DbstlException(argtype, arg, 0)
0220 {
0221 #ifdef DEBUG
0222 cerr<<"\nInvalid argument exception: "<<argtype<<"\t"<<arg;
0223 #endif
0224 }
0225
0226 COPY_CONSTRUCTOR(InvalidArgumentException)
0227 };
0228
0229
0230 class _exported NotSupportedException : public DbstlException
0231 {
0232 public:
0233 explicit NotSupportedException(const char *str) : DbstlException(str)
0234 {
0235 }
0236
0237 COPY_CONSTRUCTOR(NotSupportedException)
0238 };
0239
0240
0241 class _exported InvalidFunctionCall : public DbstlException
0242 {
0243 public:
0244 explicit InvalidFunctionCall(const char *str) : DbstlException(str)
0245 {
0246 #ifdef DEBUG
0247 cerr<<"\nInvalid function call: "<<str;
0248 #endif
0249 }
0250
0251 COPY_CONSTRUCTOR(InvalidFunctionCall)
0252 };
0253
0254 #undef COPY_CONSTRUCTOR
0255 END_NS
0256
0257 #endif