[1365] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
[1738] | 2 |
|
---|
| 3 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 4 | // Eric Aubourg
|
---|
| 5 | // Christophe Magneville
|
---|
| 6 | // Reza Ansari
|
---|
| 7 | // $Id: apexceptions.h,v 1.2 2001-11-08 15:47:44 aubourg Exp $
|
---|
| 8 |
|
---|
[1365] | 9 | #ifndef PEXCEPTIONS_SEEN
|
---|
| 10 | #define PEXCEPTIONS_SEEN
|
---|
| 11 |
|
---|
| 12 | #include "config.h"
|
---|
| 13 | #include <string>
|
---|
| 14 |
|
---|
| 15 | using namespace std;
|
---|
| 16 |
|
---|
| 17 | // Petit utilitaire pour accoler numero de ligne et nom de fichier aux messages
|
---|
| 18 | // d'exception
|
---|
| 19 | #define PExcLongMessage(a) BuildLongExceptionMessage(a,__FILE__,__LINE__)
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | //! Utility function for appending a file name and line number to a message
|
---|
| 23 | string BuildLongExceptionMessage(const char * s, const char *file, int line);
|
---|
| 24 |
|
---|
| 25 | /*! \ingroup SysTools
|
---|
| 26 | \brief Base exception class in Sophya
|
---|
| 27 |
|
---|
| 28 | Ancestor for PError and PException
|
---|
| 29 | It has a message, and an id to give more
|
---|
| 30 | information on the exception.
|
---|
| 31 | */
|
---|
| 32 | class PThrowable {
|
---|
| 33 | public:
|
---|
| 34 | //! Constructor with the message and error-id (optional) specification
|
---|
| 35 | explicit PThrowable(const string& m, int ident=0)
|
---|
| 36 | : msg(m), id(ident) {}
|
---|
| 37 | virtual ~PThrowable() { }
|
---|
| 38 | //! Returns the associated message string
|
---|
| 39 | virtual string const& Msg() const {return msg;}
|
---|
| 40 | //! Returns the associated error-id
|
---|
| 41 | virtual int Id() const {return id; }
|
---|
| 42 | private:
|
---|
| 43 | string msg;
|
---|
| 44 | int id;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | // PThrowable
|
---|
| 48 | // PError
|
---|
| 49 | // PException
|
---|
| 50 |
|
---|
| 51 | /*! \ingroup SysTools
|
---|
| 52 | \brief A PError is a serious logic error. Usually not caught... */
|
---|
| 53 | class PError : public PThrowable {
|
---|
| 54 | public:
|
---|
| 55 | explicit PError(const string& m, int id=0) : PThrowable(m,id) {}
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | /*! \ingroup SysTools
|
---|
| 59 | \brief A PException is not as serious... Can be caught. */
|
---|
| 60 | class PException : public PThrowable {
|
---|
| 61 | public:
|
---|
| 62 | explicit PException(const string& m, int id=0) : PThrowable(m,id) {}
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | // ---- Errors ----
|
---|
| 66 | // PError
|
---|
| 67 | // AllocationError
|
---|
| 68 | // NullPtrError
|
---|
| 69 | // ForbiddenError
|
---|
| 70 | // AssertionFailedError
|
---|
| 71 |
|
---|
| 72 | /*! \ingroup SysTools
|
---|
| 73 | \brief Memory allocation failure */
|
---|
| 74 | class AllocationError : public PError {
|
---|
| 75 | public:
|
---|
| 76 | explicit AllocationError(const string& m, int id=0) : PError(m,id) {}
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | /*! \ingroup SysTools
|
---|
| 80 | \brief Null pointer error */
|
---|
| 81 | class NullPtrError : public PError {
|
---|
| 82 | public:
|
---|
| 83 | explicit NullPtrError(const string& m, int id=0) : PError(m,id) {}
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | /*! \ingroup SysTools
|
---|
| 88 | \brief Calling a forbidden method, trying a forbidden operation */
|
---|
| 89 | class ForbiddenError : public PError {
|
---|
| 90 | public:
|
---|
| 91 | explicit ForbiddenError(const string& m, int id=0) : PError(m,id) {}
|
---|
| 92 | };
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | /*! \ingroup SysTools
|
---|
| 96 | \brief ASSERT macro failure. The message is the assertion... */
|
---|
| 97 | class AssertionFailedError : public PError {
|
---|
| 98 | public:
|
---|
| 99 | explicit AssertionFailedError(const string& m, int id=0) : PError(m,id) {}
|
---|
| 100 | };
|
---|
| 101 |
|
---|
| 102 | // Standard exceptions
|
---|
| 103 | //
|
---|
| 104 | // PException
|
---|
| 105 | // IOExc
|
---|
| 106 | // FileFormatExc
|
---|
| 107 | // SzMismatchError
|
---|
| 108 | // RangeCheckError
|
---|
| 109 | // ParmError
|
---|
| 110 | // TypeMismatchExc
|
---|
| 111 | // MathExc
|
---|
| 112 | // SingMatxExc
|
---|
| 113 | // DuplicateIdExc
|
---|
| 114 | // NotFoundExc
|
---|
| 115 | // CaughtSignalExc
|
---|
| 116 |
|
---|
| 117 | /*! \ingroup SysTools
|
---|
| 118 | \brief Generic IO Exception */
|
---|
| 119 | class IOExc : public PException {
|
---|
| 120 | public:
|
---|
| 121 | explicit IOExc(const string& m, int id=0) : PException(m,id) {}
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | /*! \ingroup SysTools
|
---|
| 125 | \brief Bad file format */
|
---|
| 126 | class FileFormatExc : public IOExc {
|
---|
| 127 | public:
|
---|
| 128 | explicit FileFormatExc(const string& m, int id=0) : IOExc(m,id) {}
|
---|
| 129 | };
|
---|
| 130 |
|
---|
| 131 | /*! \ingroup SysTools
|
---|
| 132 | \brief Size mismatch between objects */
|
---|
| 133 | class SzMismatchError : public PException {
|
---|
| 134 | public:
|
---|
| 135 | explicit SzMismatchError(const string& m, int id=0) : PException(m,id) {}
|
---|
| 136 | };
|
---|
| 137 |
|
---|
| 138 | /*! \ingroup SysTools
|
---|
| 139 | \brief Out of bounds for array, matrix, etc */
|
---|
| 140 | class RangeCheckError : public PException {
|
---|
| 141 | public:
|
---|
| 142 | explicit RangeCheckError(const string& m, int id=0) : PException(m,id) {}
|
---|
| 143 | };
|
---|
| 144 |
|
---|
| 145 | /*! \ingroup SysTools
|
---|
| 146 | \brief Invalid parameter to method/constructor... */
|
---|
| 147 | class ParmError : public PException {
|
---|
| 148 | public:
|
---|
| 149 | explicit ParmError(const string& m, int id=0) : PException(m,id) {}
|
---|
| 150 | };
|
---|
| 151 |
|
---|
| 152 | /*! \ingroup SysTools
|
---|
| 153 | \brief Calling a non available / not implemented method */
|
---|
| 154 | class NotAvailableOperation : public PException {
|
---|
| 155 | public:
|
---|
| 156 | explicit NotAvailableOperation(const string& m, int id=0) : PException(m,id) {}
|
---|
| 157 | };
|
---|
| 158 |
|
---|
| 159 | /*! \ingroup SysTools
|
---|
| 160 | \brief Bad data type -> keep ? */
|
---|
| 161 | class TypeMismatchExc : public PException {
|
---|
| 162 | public:
|
---|
| 163 | explicit TypeMismatchExc(const string& m, int id=0) : PException(m,id) {}
|
---|
| 164 | };
|
---|
| 165 |
|
---|
| 166 | /*! \ingroup SysTools
|
---|
| 167 | \brief Math operation exception */
|
---|
| 168 | class MathExc : public PException {
|
---|
| 169 | public:
|
---|
| 170 | explicit MathExc(const string& m, int id=0) : PException(m,id) {}
|
---|
| 171 | };
|
---|
| 172 |
|
---|
| 173 | /*! \ingroup SysTools
|
---|
| 174 | \brief Singular matrix */
|
---|
| 175 | class SingMatrixExc : public MathExc {
|
---|
| 176 | public:
|
---|
| 177 | explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {}
|
---|
| 178 | };
|
---|
| 179 |
|
---|
| 180 | /*! \ingroup SysTools
|
---|
| 181 | \brief Duplicate identifier during registration */
|
---|
| 182 | class DuplicateIdExc : public PException {
|
---|
| 183 | public:
|
---|
| 184 | explicit DuplicateIdExc(const string& m, int id=0) : PException(m,id) {}
|
---|
| 185 | };
|
---|
| 186 |
|
---|
| 187 | /*! \ingroup SysTools
|
---|
| 188 | \brief Not found identifier */
|
---|
| 189 | class NotFoundExc : public PException {
|
---|
| 190 | public:
|
---|
| 191 | explicit NotFoundExc(const string& m, int id=0) : PException(m,id) {}
|
---|
| 192 | };
|
---|
| 193 |
|
---|
| 194 | /*! \ingroup SysTools
|
---|
| 195 | \brief Generated exception when processing a signal */
|
---|
| 196 | class CaughtSignalExc : public PException {
|
---|
| 197 | public:
|
---|
| 198 | explicit CaughtSignalExc(const string& m, int id=0) : PException(m,id) {}
|
---|
| 199 | };
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | #define ASSERT(_a_) if (!(_a_)) { \
|
---|
| 204 | cerr << "Assertion failed " #_a_ " file " __FILE__ " line " << __LINE__ \
|
---|
| 205 | << endl; \
|
---|
| 206 | throw(AssertionFailedError(#_a_)); }
|
---|
| 207 |
|
---|
| 208 | #define FAILNIL(_x_) \
|
---|
| 209 | {if (!(_x_)) throw(NullPtrError(#_x_))}
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | #endif
|
---|