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

Last change on this file since 895 was 895, checked in by ansari, 25 years ago

Documentation de fichiers - Reza 12/4/2000

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