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

Last change on this file since 821 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
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
[773]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
[552]14namespace SOPHYA {
[242]15
[773]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
[242]19 // Ancestor for PError and PException
[256]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;
[242]31 };
[256]32
[242]33 // A PError is a serious logic error. Usually not caught...
34 class PError : public PThrowable {
[256]35 public:
36 explicit PError(const string& m, int id=0) : PThrowable(m,id) {}
[242]37 };
38
39 // A PException is not as serious... Can be caught.
40 class PException : public PThrowable {
[256]41 public:
42 explicit PException(const string& m, int id=0) : PThrowable(m,id) {}
[242]43 };
[256]44
[242]45 // Errors
[256]46 // Memory allocation failure
[242]47 class AllocationError : public PError {
[256]48 public:
49 explicit AllocationError(const string& m, int id=0) : PError(m,id) {}
[242]50 };
51
[256]52 // Null pointer error
[242]53 class NullPtrError : public PError {
[256]54 public:
55 explicit NullPtrError(const string& m, int id=0) : PError(m,id) {}
[242]56 };
[256]57
58 // Size mismatch between objects
[242]59 class SzMismatchError : public PError {
[256]60 public:
61 explicit SzMismatchError(const string& m, int id=0) : PError(m,id) {}
[242]62 };
[256]63
64 // Out of bounds for array, matrix, etc.
[242]65 class RangeCheckError : public PError {
[256]66 public:
67 explicit RangeCheckError(const string& m, int id=0) : PError(m,id) {}
[242]68 };
[256]69
70 // Invalid parameter to method/constructor...
[242]71 class ParmError : public PError {
[256]72 public:
73 explicit ParmError(const string& m, int id=0) : PError(m,id) {}
[242]74 };
[256]75
76 // Calling a forbidden method, trying a forbidden operation
[242]77 class ForbiddenError : public PError {
[256]78 public:
79 explicit ForbiddenError(const string& m, int id=0) : PError(m,id) {}
[242]80 };
[749]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 };
[256]87
88 // ASSERT macro failure. The message is the assertion...
[242]89 class AssertionFailedError : public PError {
[256]90 public:
91 explicit AssertionFailedError(const string& m, int id=0) : PError(m,id) {}
[242]92 };
[256]93
[242]94 // Standard exceptions
[256]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) {}
[242]109 };
110
[256]111 // Bad type -> keep ?
112 class TypeMismatchExc : public PException {
113 public:
114 explicit TypeMismatchExc(const string& m, int id=0) : PException(m,id) {}
[242]115 };
[256]116
117 class MathExc : public PException {
118 public:
119 explicit MathExc(const string& m, int id=0) : PException(m,id) {}
[242]120 };
[256]121
[242]122 class DuplicateIdExc : public PException {
[256]123 public:
124 explicit DuplicateIdExc(const string& m, int id=0) : PException(m,id) {}
[242]125 };
[256]126
[242]127 class NotFoundExc : public PException {
[256]128 public:
129 explicit NotFoundExc(const string& m, int id=0) : PException(m,id) {}
[242]130 };
[256]131
[242]132 class CaughtSignalExc : public PException {
[256]133 public:
134 explicit CaughtSignalExc(const string& m, int id=0) : PException(m,id) {}
[242]135 };
[256]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 };
[242]142
[256]143 class SingMatrixExc : public MathExc {
144 public:
145 explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {}
[242]146 };
147
[256]148
[242]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("")
[256]192#define fileErr IOExc("")
[242]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.