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

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

Ajout de l'argument bool zero ds NDataBlock<T>::Alloc()
Fonction pour construire un message d'exception avec num de ligne et
nom de fichier ds pexceptions.h .cc

Reza 10/3/2000

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