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

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

ppersist + pexc

File size: 3.6 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 <exception>
7#include <string>
8
9using namespace std;
10
11namespace PlanckDPC {
12
13 // Ancestor for PError and PException
14 class PThrowable { // : public exception {
15 public:
16 explicit PThrowable(const string& m) : msg(m) {}
17 virtual string const& Msg() const {return msg;}
18 private:
19 string msg;
20 };
21
22 // A PError is a serious logic error. Usually not caught...
23 class PError : public PThrowable {
24 public:
25 explicit PError(const string& m) : PThrowable(m) {}
26 };
27
28 // A PException is not as serious... Can be caught.
29 class PException : public PThrowable {
30 public:
31 explicit PException(const string& m) : PThrowable(m) {}
32 };
33
34 // Errors
35 class AllocationError : public PError {
36 public:
37 explicit AllocationError(const string& m) : PError(m) {}
38 };
39
40 class NullPtrError : public PError {
41 public:
42 explicit NullPtrError(const string& m) : PError(m) {}
43 };
44
45 class SzMismatchError : public PError {
46 public:
47 explicit SzMismatchError(const string& m) : PError(m) {}
48 };
49
50 class RangeCheckError : public PError {
51 public:
52 explicit RangeCheckError(const string& m) : PError(m) {}
53 };
54
55 class ParmError : public PError {
56 public:
57 explicit ParmError(const string& m) : PError(m) {}
58 };
59
60 class ForbiddenError : public PError {
61 public:
62 explicit ForbiddenError(const string& m) : PError(m) {}
63 };
64
65 class AssertionFailedError : public PError {
66 public:
67 explicit AssertionFailedError(const string& m) : PError(m) {}
68 };
69
70 // Standard exceptions
71 class TypeMismatchExc : public PException {
72 public:
73 explicit TypeMismatchExc(const string& m) : PException(m) {}
74 };
75
76 class FileExc : public PException {
77 public:
78 explicit FileExc(const string& m) : PException(m) {}
79 };
80
81 class FileFormatExc : public PException {
82 public:
83 explicit FileFormatExc(const string& m) : PException(m) {}
84 };
85
86 class DuplicateIdExc : public PException {
87 public:
88 explicit DuplicateIdExc(const string& m) : PException(m) {}
89 };
90
91 class NotFoundExc : public PException {
92 public:
93 explicit NotFoundExc(const string& m) : PException(m) {}
94 };
95
96 class CaughtSignalExc : public PException {
97 public:
98 explicit CaughtSignalExc(const string& m) : PException(m) {}
99 };
100
101 class SingMatrixExc : public PException {
102 public:
103 explicit SingMatrixExc(const string& m) : PException(m) {}
104 };
105
106
107}
108
109
110#define ASSERT(_a_) if (!(_a_)) { \
111 cerr << "Assertion failed " #_a_ " file " __FILE__ " line " << __LINE__ \
112 << endl; \
113 throw(AssertionFailedError(#_a_)); }
114
115#define FAILNIL(_x_) \
116 {if (!(_x_)) throw(NullPtrError(#_x_))}
117
118void InitFailNewHandler();
119
120
121// Compatibility with EROS-PEIDA exceptions
122
123#define EXC_ABORT_NEG(_x)
124#define EXC_ABORT_ALL(_x)
125
126#define EXC_AWARE
127
128#define END_CONSTRUCTOR
129
130#define TRY try
131#define CATCH(_var) catch(long _var)
132#define CATCHALL catch(...)
133#define ENDTRY
134
135#define THROW(_i) throw( _i);
136
137#define THROW_ THROW(0)
138
139#define THROW_SAME throw;
140
141#define RETURN(x) return(x)
142#define RETURN_ return
143
144#define rangeCheckErr RangeCheckError("")
145#define typeMismatchErr TypeMismatchExc("")
146#define allocationErr AllocationError("")
147#define parmErr ParmError("")
148#define inconsistentErr ParmError("")
149#define sizeMismatchErr SzMismatchError("")
150#define fileErr FileExc("")
151#define nullPtrErr NullPtrError("")
152#define singMatxErr SingMatrixExc("")
153
154#define DBASSERT(_x_) ASSERT(_x_)
155
156#endif
Note: See TracBrowser for help on using the repository browser.