| 1 | // This may look like C code, but it is really -*- C++ -*-
|
|---|
| 2 | #ifndef PEXCEPTIONS_SEEN
|
|---|
| 3 | #define PEXCEPTIONS_SEEN
|
|---|
| 4 |
|
|---|
| 5 | #include "machdefs.h"
|
|---|
| 6 | //#include <exception>
|
|---|
| 7 | #include <string>
|
|---|
| 8 |
|
|---|
| 9 | using namespace std;
|
|---|
| 10 |
|
|---|
| 11 | namespace PlanckDPC {
|
|---|
| 12 |
|
|---|
| 13 | // Ancestor for PError and PException
|
|---|
| 14 | class PThrowable { // : public exception {
|
|---|
| 15 | public:
|
|---|
| 16 | explicit PThrowable(const string& m) : msg(m) {}
|
|---|
| 17 | virtual ~PThrowable() { }
|
|---|
| 18 | virtual string const& Msg() const {return msg;}
|
|---|
| 19 | private:
|
|---|
| 20 | string msg;
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | // A PError is a serious logic error. Usually not caught...
|
|---|
| 24 | class PError : public PThrowable {
|
|---|
| 25 | public:
|
|---|
| 26 | explicit PError(const string& m) : PThrowable(m) {}
|
|---|
| 27 | };
|
|---|
| 28 |
|
|---|
| 29 | // A PException is not as serious... Can be caught.
|
|---|
| 30 | class PException : public PThrowable {
|
|---|
| 31 | public:
|
|---|
| 32 | explicit PException(const string& m) : PThrowable(m) {}
|
|---|
| 33 | };
|
|---|
| 34 |
|
|---|
| 35 | // Errors
|
|---|
| 36 | class AllocationError : public PError {
|
|---|
| 37 | public:
|
|---|
| 38 | explicit AllocationError(const string& m) : PError(m) {}
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | class NullPtrError : public PError {
|
|---|
| 42 | public:
|
|---|
| 43 | explicit NullPtrError(const string& m) : PError(m) {}
|
|---|
| 44 | };
|
|---|
| 45 |
|
|---|
| 46 | class SzMismatchError : public PError {
|
|---|
| 47 | public:
|
|---|
| 48 | explicit SzMismatchError(const string& m) : PError(m) {}
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | class RangeCheckError : public PError {
|
|---|
| 52 | public:
|
|---|
| 53 | explicit RangeCheckError(const string& m) : PError(m) {}
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | class ParmError : public PError {
|
|---|
| 57 | public:
|
|---|
| 58 | explicit ParmError(const string& m) : PError(m) {}
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | class ForbiddenError : public PError {
|
|---|
| 62 | public:
|
|---|
| 63 | explicit ForbiddenError(const string& m) : PError(m) {}
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 | class AssertionFailedError : public PError {
|
|---|
| 67 | public:
|
|---|
| 68 | explicit AssertionFailedError(const string& m) : PError(m) {}
|
|---|
| 69 | };
|
|---|
| 70 |
|
|---|
| 71 | // Standard exceptions
|
|---|
| 72 | class TypeMismatchExc : public PException {
|
|---|
| 73 | public:
|
|---|
| 74 | explicit TypeMismatchExc(const string& m) : PException(m) {}
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | class FileExc : public PException {
|
|---|
| 78 | public:
|
|---|
| 79 | explicit FileExc(const string& m) : PException(m) {}
|
|---|
| 80 | };
|
|---|
| 81 |
|
|---|
| 82 | class FileFormatExc : public PException {
|
|---|
| 83 | public:
|
|---|
| 84 | explicit FileFormatExc(const string& m) : PException(m) {}
|
|---|
| 85 | };
|
|---|
| 86 |
|
|---|
| 87 | class DuplicateIdExc : public PException {
|
|---|
| 88 | public:
|
|---|
| 89 | explicit DuplicateIdExc(const string& m) : PException(m) {}
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | class NotFoundExc : public PException {
|
|---|
| 93 | public:
|
|---|
| 94 | explicit NotFoundExc(const string& m) : PException(m) {}
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | class CaughtSignalExc : public PException {
|
|---|
| 98 | public:
|
|---|
| 99 | explicit CaughtSignalExc(const string& m) : PException(m) {}
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | class SingMatrixExc : public PException {
|
|---|
| 103 | public:
|
|---|
| 104 | explicit SingMatrixExc(const string& m) : PException(m) {}
|
|---|
| 105 | };
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 | #define ASSERT(_a_) if (!(_a_)) { \
|
|---|
| 112 | cerr << "Assertion failed " #_a_ " file " __FILE__ " line " << __LINE__ \
|
|---|
| 113 | << endl; \
|
|---|
| 114 | throw(AssertionFailedError(#_a_)); }
|
|---|
| 115 |
|
|---|
| 116 | #define FAILNIL(_x_) \
|
|---|
| 117 | {if (!(_x_)) throw(NullPtrError(#_x_))}
|
|---|
| 118 |
|
|---|
| 119 | void InitFailNewHandler();
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | // Compatibility with EROS-PEIDA exceptions
|
|---|
| 123 |
|
|---|
| 124 | #define EXC_ABORT_NEG(_x)
|
|---|
| 125 | #define EXC_ABORT_ALL(_x)
|
|---|
| 126 |
|
|---|
| 127 | #define EXC_AWARE
|
|---|
| 128 |
|
|---|
| 129 | #define END_CONSTRUCTOR
|
|---|
| 130 |
|
|---|
| 131 | #define TRY try
|
|---|
| 132 | #define CATCH(_var) catch(long _var)
|
|---|
| 133 | #define CATCHALL catch(...)
|
|---|
| 134 | #define ENDTRY
|
|---|
| 135 |
|
|---|
| 136 | #define THROW(_i) throw( _i);
|
|---|
| 137 |
|
|---|
| 138 | #define THROW_ THROW(0)
|
|---|
| 139 |
|
|---|
| 140 | #define THROW_SAME throw;
|
|---|
| 141 |
|
|---|
| 142 | #define RETURN(x) return(x)
|
|---|
| 143 | #define RETURN_ return
|
|---|
| 144 |
|
|---|
| 145 | #define rangeCheckErr RangeCheckError("")
|
|---|
| 146 | #define typeMismatchErr TypeMismatchExc("")
|
|---|
| 147 | #define allocationErr AllocationError("")
|
|---|
| 148 | #define parmErr ParmError("")
|
|---|
| 149 | #define inconsistentErr ParmError("")
|
|---|
| 150 | #define sizeMismatchErr SzMismatchError("")
|
|---|
| 151 | #define fileErr FileExc("")
|
|---|
| 152 | #define nullPtrErr NullPtrError("")
|
|---|
| 153 | #define singMatxErr SingMatrixExc("")
|
|---|
| 154 |
|
|---|
| 155 | #define DBASSERT(_x_) ASSERT(_x_)
|
|---|
| 156 |
|
|---|
| 157 | #endif
|
|---|