/usr/include/dbstl_exception.h is in libdb5.3-stl-dev 5.3.28-9+deb8u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009, 2013 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
#ifndef _DB_STL_EXCEPTION_H
#define _DB_STL_EXCEPTION_H
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <exception>
#include "dbstl_common.h"
START_NS(dbstl)
using std::cerr;
// Internally used only.
void _exported throw_bdb_exception(const char *caller, int err_ret);
#define COPY_CONSTRUCTOR(type) type(const type& t) : DbstlException(t){}
/** \defgroup Exception_classes_group dbstl exception classes
dbstl throws several types of exceptions on several kinds of errors, the
exception classes form a class hiarachy. First, there is the DbstlException,
which is the base class for all types of dbstl specific concrete exception
classes.
DbstlException inherits from the class DbException of Berkeley DB C++ API. Since
DbException class inherits from C++ STL exception base class std::exception,
you can make use of all Berkeley DB C++ and dbstl API exceptions in the same
way you use the C++ std::exception class.
Besides exceptions of DbstlException and its subclasses, dbstl may also
throw exceptions of DbException and its subclasses, which happens when a
Berkeley DB call failed. So you should use the same way you catch Berkeley DB
C++ API exceptions when you want to catch exceptions throw by Berkeley DB
operations.
When an exception occurs, dbstl initialize an local exception object on the
stack and throws the exception object, so you should catch an exception like
this:
try {
// dbstl operations
}
catch(DbstlException ex){
// Exception handling
throw ex; // Optionally throw ex again
}
@{
*/
/// Base class of all dbstl exception classes. It is derived from Berkeley
/// DB C++ API DbException class to maintain consistency with all
/// Berkeley DB exceptions.
///
class _exported DbstlException : public DbException
{
public:
explicit DbstlException(const char *msg) : DbException(msg) {}
DbstlException(const char *msg, int err) : DbException(msg, err) {}
DbstlException(const DbstlException&ex) : DbException(ex) {}
explicit DbstlException(int err) : DbException(err) {}
DbstlException(const char *prefix, const char *msg, int err) :
DbException(prefix, msg, err) {}
const DbstlException& operator=(const DbstlException&exobj)
{
ASSIGNMENT_PREDCOND(exobj)
DbException::operator =
(dynamic_cast<const DbException&>(exobj));
return exobj;
}
virtual ~DbstlException() throw(){}
};
/// Failed to allocate memory because memory is not enough.
class _exported NotEnoughMemoryException : public DbstlException
{
size_t failed_size; // The size of the failed allocation.
public:
NotEnoughMemoryException(const char *msg, size_t sz)
: DbstlException(msg)
{
failed_size = sz;
}
NotEnoughMemoryException(const NotEnoughMemoryException &ex)
: DbstlException(ex)
{
this->failed_size = ex.failed_size;
}
};
/// The iterator has inconsistent status, it is unable to be used any more.
class _exported InvalidIteratorException : public DbstlException
{
public:
InvalidIteratorException() : DbstlException("Invalid Iterator")
{
}
explicit InvalidIteratorException(int error_code) :
DbstlException("Invalid Iterator", error_code)
{
}
COPY_CONSTRUCTOR(InvalidIteratorException)
};
/// The cursor has inconsistent status, it is unable to be used any more.
class _exported InvalidCursorException : public DbstlException
{
public:
InvalidCursorException() : DbstlException("Invalid cursor")
{
}
explicit InvalidCursorException(int error_code) :
DbstlException("Invalid cursor", error_code)
{
}
COPY_CONSTRUCTOR(InvalidCursorException)
};
/// The Dbt object has inconsistent status or has no valid data, it is unable
/// to be used any more.
class _exported InvalidDbtException : public DbstlException
{
public:
InvalidDbtException() : DbstlException("Invalid Dbt object")
{
}
explicit InvalidDbtException(int error_code) :
DbstlException("Invalid Dbt object", error_code)
{
}
COPY_CONSTRUCTOR(InvalidDbtException)
};
/// The assertions inside dbstl failed. The code file name and line number
/// will be passed to the exception object of this class.
class _exported FailedAssertionException : public DbstlException
{
private:
char *err_msg_;
public:
virtual const char *what() const throw()
{
return err_msg_;
}
FailedAssertionException(const char *fname, size_t lineno,
const char *msg) : DbstlException(0)
{
u_int32_t sz;
char *str;
str = (char *)DbstlMalloc(sz = (u_int32_t)(strlen(msg) +
strlen(fname) + 128));
_snprintf(str, sz,
"In file %s at line %u, %s expression failed",
fname, (unsigned int)lineno, msg);
err_msg_ = str;
#ifdef DEBUG
fprintf(stderr, "%s", str);
#endif
}
FailedAssertionException(const FailedAssertionException&ex) :
DbstlException(ex)
{
err_msg_ = (char *)DbstlMalloc((u_int32_t)
strlen(ex.err_msg_) + 1);
strcpy(err_msg_, ex.err_msg_);
}
virtual ~FailedAssertionException() throw()
{
free(err_msg_);
}
};
/// There is no such key in the database. The key can't not be passed into
/// the exception instance because this class has to be a class template for
/// that to work.
class _exported NoSuchKeyException : public DbstlException
{
public:
NoSuchKeyException()
: DbstlException("\nNo such key in the container.")
{
}
COPY_CONSTRUCTOR(NoSuchKeyException)
};
/// Some argument of a function is invalid.
class _exported InvalidArgumentException : public DbstlException
{
public:
explicit InvalidArgumentException(const char *errmsg) :
DbstlException(errmsg)
{
#ifdef DEBUG
cerr<<errmsg;
#endif
}
InvalidArgumentException(const char *argtype, const char *arg) :
DbstlException(argtype, arg, 0)
{
#ifdef DEBUG
cerr<<"\nInvalid argument exception: "<<argtype<<"\t"<<arg;
#endif
}
COPY_CONSTRUCTOR(InvalidArgumentException)
};
/// The function called is not supported in this class.
class _exported NotSupportedException : public DbstlException
{
public:
explicit NotSupportedException(const char *str) : DbstlException(str)
{
}
COPY_CONSTRUCTOR(NotSupportedException)
};
/// The function can not be called in this context or in current configurations.
class _exported InvalidFunctionCall : public DbstlException
{
public:
explicit InvalidFunctionCall(const char *str) : DbstlException(str)
{
#ifdef DEBUG
cerr<<"\nInvalid function call: "<<str;
#endif
}
COPY_CONSTRUCTOR(InvalidFunctionCall)
};
/** @}*/
#undef COPY_CONSTRUCTOR
END_NS
#endif //_DB_STL_EXCEPTION_H
|