source: Sophya/trunk/SophyaLib/BaseTools/pexceptions.h@ 749

Last change on this file since 749 was 749, checked in by ansari, 26 years ago

Nouveau type d'exception - Reza 2/3/1000

File size: 4.7 KB
RevLine 
[242]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 <string>
7
8using namespace std;
9
[552]10namespace SOPHYA {
[242]11
12 // Ancestor for PError and PException
[256]13 // It has a message, and an id to give more
14 // information on the exception.
15 class PThrowable {
16 public:
17 explicit PThrowable(const string& m, int ident=0)
18 : msg(m), id(ident) {}
19 virtual ~PThrowable() { }
20 virtual string const& Msg() const {return msg;}
21 private:
22 string msg;
23 int id;
[242]24 };
[256]25
[242]26 // A PError is a serious logic error. Usually not caught...
27 class PError : public PThrowable {
[256]28 public:
29 explicit PError(const string& m, int id=0) : PThrowable(m,id) {}
[242]30 };
31
32 // A PException is not as serious... Can be caught.
33 class PException : public PThrowable {
[256]34 public:
35 explicit PException(const string& m, int id=0) : PThrowable(m,id) {}
[242]36 };
[256]37
[242]38 // Errors
[256]39 // Memory allocation failure
[242]40 class AllocationError : public PError {
[256]41 public:
42 explicit AllocationError(const string& m, int id=0) : PError(m,id) {}
[242]43 };
44
[256]45 // Null pointer error
[242]46 class NullPtrError : public PError {
[256]47 public:
48 explicit NullPtrError(const string& m, int id=0) : PError(m,id) {}
[242]49 };
[256]50
51 // Size mismatch between objects
[242]52 class SzMismatchError : public PError {
[256]53 public:
54 explicit SzMismatchError(const string& m, int id=0) : PError(m,id) {}
[242]55 };
[256]56
57 // Out of bounds for array, matrix, etc.
[242]58 class RangeCheckError : public PError {
[256]59 public:
60 explicit RangeCheckError(const string& m, int id=0) : PError(m,id) {}
[242]61 };
[256]62
63 // Invalid parameter to method/constructor...
[242]64 class ParmError : public PError {
[256]65 public:
66 explicit ParmError(const string& m, int id=0) : PError(m,id) {}
[242]67 };
[256]68
69 // Calling a forbidden method, trying a forbidden operation
[242]70 class ForbiddenError : public PError {
[256]71 public:
72 explicit ForbiddenError(const string& m, int id=0) : PError(m,id) {}
[242]73 };
[749]74
75 // Calling a non available / not implemented method
76 class NotAvailableOperation : public PException {
77 public:
78 explicit NotAvailableOperation(const string& m, int id=0) : PException(m,id) {}
79 };
[256]80
81 // ASSERT macro failure. The message is the assertion...
[242]82 class AssertionFailedError : public PError {
[256]83 public:
84 explicit AssertionFailedError(const string& m, int id=0) : PError(m,id) {}
[242]85 };
[256]86
[242]87 // Standard exceptions
[256]88 //
89 // PException
90 // IOExc
91 // FileFormatExc
92 // TypeMismatchExc
93 // DuplicateIdExc
94 // NotFoundExc
95 // MathExc
96 // SingMatxExc
97
98 // generic IO Exception
99 class IOExc : public PException {
100 public:
101 explicit IOExc(const string& m, int id=0) : PException(m,id) {}
[242]102 };
103
[256]104 // Bad type -> keep ?
105 class TypeMismatchExc : public PException {
106 public:
107 explicit TypeMismatchExc(const string& m, int id=0) : PException(m,id) {}
[242]108 };
[256]109
110 class MathExc : public PException {
111 public:
112 explicit MathExc(const string& m, int id=0) : PException(m,id) {}
[242]113 };
[256]114
[242]115 class DuplicateIdExc : public PException {
[256]116 public:
117 explicit DuplicateIdExc(const string& m, int id=0) : PException(m,id) {}
[242]118 };
[256]119
[242]120 class NotFoundExc : public PException {
[256]121 public:
122 explicit NotFoundExc(const string& m, int id=0) : PException(m,id) {}
[242]123 };
[256]124
[242]125 class CaughtSignalExc : public PException {
[256]126 public:
127 explicit CaughtSignalExc(const string& m, int id=0) : PException(m,id) {}
[242]128 };
[256]129
130 // Bad file format
131 class FileFormatExc : public IOExc {
132 public:
133 explicit FileFormatExc(const string& m, int id=0) : IOExc(m,id) {}
134 };
[242]135
[256]136 class SingMatrixExc : public MathExc {
137 public:
138 explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {}
[242]139 };
140
[256]141
[242]142}
143
144
145#define ASSERT(_a_) if (!(_a_)) { \
146 cerr << "Assertion failed " #_a_ " file " __FILE__ " line " << __LINE__ \
147 << endl; \
148 throw(AssertionFailedError(#_a_)); }
149
150#define FAILNIL(_x_) \
151 {if (!(_x_)) throw(NullPtrError(#_x_))}
152
153void InitFailNewHandler();
154
155
156// Compatibility with EROS-PEIDA exceptions
157
158#define EXC_ABORT_NEG(_x)
159#define EXC_ABORT_ALL(_x)
160
161#define EXC_AWARE
162
163#define END_CONSTRUCTOR
164
165#define TRY try
166#define CATCH(_var) catch(long _var)
167#define CATCHALL catch(...)
168#define ENDTRY
169
170#define THROW(_i) throw( _i);
171
172#define THROW_ THROW(0)
173
174#define THROW_SAME throw;
175
176#define RETURN(x) return(x)
177#define RETURN_ return
178
179#define rangeCheckErr RangeCheckError("")
180#define typeMismatchErr TypeMismatchExc("")
181#define allocationErr AllocationError("")
182#define parmErr ParmError("")
183#define inconsistentErr ParmError("")
184#define sizeMismatchErr SzMismatchError("")
[256]185#define fileErr IOExc("")
[242]186#define nullPtrErr NullPtrError("")
187#define singMatxErr SingMatrixExc("")
188
189#define DBASSERT(_x_) ASSERT(_x_)
190
191#endif
Note: See TracBrowser for help on using the repository browser.