Mercurial > hg > kwantix
annotate include/error.hpp @ 15:5144dd3c5468
Almost completed adding all Doxygen docstrings.
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Fri, 08 Aug 2008 00:08:57 -0500 |
parents | 6e06eb6ec448 |
children | 29a7b95c2805 |
rev | line source |
---|---|
0 | 1 /*! \file error.hpp |
2 * \brief Throw exceptions instead of using GSL error handler function which | |
3 * prefers to call abort(). | |
4 * | |
5 | |
6 * Remember to put `gsl_set_error_handler(&errorHandler);' in the | |
7 * main() loops when including this header file; otherwise it's | |
8 * useless! | |
9 */ | |
10 | |
12
6e06eb6ec448
Trivial change in include guards.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
4
diff
changeset
|
11 #ifndef __ERROR_HPP__ |
6e06eb6ec448
Trivial change in include guards.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
4
diff
changeset
|
12 #define __ERROR_HPP__ |
0 | 13 |
14 #include <gsl/gsl_errno.h> | |
15 #include <string> | |
16 | |
17 /// Exception classes in this namespace | |
18 namespace error_handling{ | |
19 //Structs to be thrown as exceptions | |
20 using std::string; | |
21 | |
22 /// generic error and base struct. /*GSL_FAILURE = -1,*/ | |
23 class error{ | |
24 public: | |
25 std::string reason, file; | |
26 int line; | |
27 error(){}; | |
28 error(string r, string f, int l) : | |
29 reason(r), file(f), line(l) {}; | |
30 | |
31 }; | |
32 | |
33 struct noConvergence ; | |
34 struct badDomain ; | |
35 struct badRange ; | |
36 struct badPointer ; | |
37 struct badArgument ; | |
38 struct failure ; | |
39 struct failedFactorisation ; | |
40 struct failedSanity ; | |
41 struct outOfMemory ; | |
42 struct badFunction ; | |
43 struct runAway ; | |
44 struct maxIterations ; | |
45 struct divideByZero ; | |
46 struct badTolerance ; | |
47 struct aboveTolerance ; | |
48 struct underflow ; | |
49 struct overflow ; | |
50 struct lossOfAccuracy ; | |
51 struct roundOffError ; | |
52 struct inconformantSizes ; | |
53 struct matrixNotSquare ; | |
54 struct singularityFound ; | |
55 struct integralOrSeriesDivergent ; | |
56 struct badHardware ; | |
57 struct notImplemented ; | |
58 struct cacheLimitExceeded ; | |
59 struct tableLimitExceeded ; | |
60 struct iterationNotProgressing ; | |
61 struct jacobiansNotImprovingSolution ; | |
62 | |
63 struct cannotReachToleranceInF ; | |
64 struct cannotReachToleranceInX ; | |
65 struct cannotReachToleranceInGradient ; | |
66 struct endOfFile ; | |
67 | |
68 /*! \brief Custom error handler to be used for GSL. | |
69 * | |
70 * Throw exceptions instead of calling abort(). | |
71 * | |
72 * Remember to put `gsl_set_error_handler(&errorHandler);' in the | |
73 * main() loops when including this header file; otherwise it's | |
74 * useless! | |
75 */ | |
76 void errorHandler(const char * reason, const char * file, | |
77 int line, int gsl_errno); | |
78 } | |
79 | |
80 | |
81 //A few more details about the structs we're throwing as exceptions. | |
82 namespace error_handling{ | |
83 using std::string; | |
84 | |
85 ///GSL_CONTINUE = -2, /* iteration has not converged */ | |
86 struct noConvergence : public error { | |
87 noConvergence() {}; | |
88 noConvergence(string r, string f, int l) : | |
89 error(r,f,l) {}; | |
90 }; | |
91 | |
92 ///GSL_EDOM = 1, /* input domain error, e.g sqrt(-1) */ | |
93 struct badDomain : public error { | |
94 badDomain() {}; | |
95 badDomain(string r, string f, int l) : | |
96 error(r,f,l) {}; | |
97 }; | |
98 | |
99 ///GSL_ERANGE = 2, /* output range error, e.g. exp(1e100) */ | |
100 struct badRange : public error { | |
101 badRange() {}; | |
102 badRange(string r, string f, int l) : | |
103 error(r,f,l) {}; | |
104 }; | |
105 | |
106 ///GSL_EFAULT = 3, /* invalid pointer */ | |
107 struct badPointer : public error { | |
108 badPointer() {}; | |
109 badPointer(string r, string f, int l) : | |
110 error(r,f,l) {}; | |
111 }; | |
112 | |
113 ///GSL_EINVAL = 4, /* invalid argument supplied by user */ | |
114 struct badArgument : public error { | |
115 badArgument() {}; | |
116 badArgument(string r, string f, int l) : | |
117 error(r,f,l) {}; | |
118 }; | |
119 | |
120 ///GSL_EFAILED = 5, /* generic failure */ | |
121 struct failure : public error { | |
122 failure() {}; | |
123 failure(string r, string f, int l) : | |
124 error(r,f,l) {}; | |
125 }; | |
126 | |
127 ///GSL_EFACTOR = 6, /* factorization failed */ | |
128 struct failedFactorisation : public error { | |
129 failedFactorisation() {}; | |
130 failedFactorisation(string r, string f, int l) : | |
131 error(r,f,l) {}; | |
132 }; | |
133 | |
134 ///GSL_ESANITY = 7, /* sanity check failed - shouldn't happen */ | |
135 struct failedSanity : public error { | |
136 failedSanity() {}; | |
137 failedSanity(string r, string f, int l) : | |
138 error(r,f,l) {}; | |
139 }; | |
140 | |
141 ///GSL_ENOMEM = 8, /* malloc failed */ | |
142 struct outOfMemory : public error { | |
143 outOfMemory() {}; | |
144 outOfMemory(string r, string f, int l) : | |
145 error(r,f,l) {}; | |
146 }; | |
147 | |
148 ///GSL_EBADFUNC = 9, /* problem with user-supplied function */ | |
149 struct badFunction : public error { | |
150 badFunction() {}; | |
151 badFunction(string r, string f, int l) : | |
152 error(r,f,l) {}; | |
153 }; | |
154 | |
155 ///GSL_ERUNAWAY = 10, /* iterative process is out of control */ | |
156 struct runAway : public error { | |
157 runAway() {}; | |
158 runAway(string r, string f, int l) : | |
159 error(r,f,l) {}; | |
160 }; | |
161 | |
162 ///GSL_EMAXITER = 11, /* exceeded max number of iterations */ | |
163 struct maxIterations : public error { | |
164 maxIterations() {}; | |
165 maxIterations(string r, string f, int l) : | |
166 error(r,f,l) {}; | |
167 }; | |
168 | |
169 ///GSL_EZERODIV = 12, /* tried to divide by zero */ | |
170 struct divideByZero : public error { | |
171 divideByZero() {}; | |
172 divideByZero(string r, string f, int l) : | |
173 error(r,f,l) {}; | |
174 }; | |
175 | |
176 ///GSL_EBADTOL = 13, /* user specified an invalid tolerance */ | |
177 struct badTolerance : public error { | |
178 badTolerance() {}; | |
179 badTolerance(string r, string f, int l) : | |
180 error(r,f,l) {}; | |
181 }; | |
182 | |
183 ///GSL_ETOL = 14, /* failed to reach the specified tolerance */ | |
184 struct aboveTolerance : public error { | |
185 aboveTolerance() {}; | |
186 aboveTolerance(string r, string f, int l) : | |
187 error(r,f,l) {}; | |
188 }; | |
189 | |
190 ///GSL_EUNDRFLW = 15, /* underflow */ | |
191 struct underflow : public error { | |
192 underflow() {}; | |
193 underflow(string r, string f, int l) : | |
194 error(r,f,l) {}; | |
195 }; | |
196 | |
197 ///GSL_EOVRFLW = 16, /* overflow */ | |
198 struct overflow : public error { | |
199 overflow() {}; | |
200 overflow(string r, string f, int l) : | |
201 error(r,f,l) {}; | |
202 }; | |
203 | |
204 ///GSL_ELOSS = 17, /* loss of accuracy */ | |
205 struct lossOfAccuracy : public error { | |
206 lossOfAccuracy() {}; | |
207 lossOfAccuracy(string r, string f, int l) : | |
208 error(r,f,l) {}; | |
209 }; | |
210 | |
211 ///GSL_EROUND = 18, /* failed because of roundoff error */ | |
212 struct roundOffError : public error { | |
213 roundOffError() {}; | |
214 roundOffError(string r, string f, int l) : | |
215 error(r,f,l) {}; | |
216 }; | |
217 | |
218 ///GSL_EBADLEN = 19, /* matrix, vector lengths are not conformant */ | |
219 struct inconformantSizes : public error { | |
220 inconformantSizes() {}; | |
221 inconformantSizes(string r, string f, int l) : | |
222 error(r,f,l) {}; | |
4
9d4fda54a41d
Buggy, must check why interpolator assignment destroys precomputed
Jordi Guitérrez Hermoso <jordigh@gmail.com>
parents:
0
diff
changeset
|
223 size_t n_A, m_A, n_B, m_B; |
0 | 224 }; |
225 | |
226 ///GSL_ENOTSQR = 20, /* matrix not square */ | |
227 struct matrixNotSquare : public error { | |
228 matrixNotSquare() {}; | |
229 matrixNotSquare(string r, string f, int l) : | |
230 error(r,f,l) {}; | |
231 }; | |
232 | |
233 ///GSL_ESING = 21, /* apparent singularity detected */ | |
234 struct singularityFound : public error { | |
235 singularityFound() {}; | |
236 singularityFound(string r, string f, int l) : | |
237 error(r,f,l) {}; | |
238 }; | |
239 | |
240 ///GSL_EDIVERGE = 22, /* integral or series is divergent */ | |
241 struct integralOrSeriesDivergent : public error { | |
242 integralOrSeriesDivergent() {}; | |
243 integralOrSeriesDivergent(string r, string f, int l) : | |
244 error(r,f,l) {}; | |
245 }; | |
246 | |
247 ///GSL_EUNSUP = 23, /* requested feature is not supported by the hardware */ | |
248 struct badHardware : public error { | |
249 badHardware() {}; | |
250 badHardware(string r, string f, int l) : | |
251 error(r,f,l) {}; | |
252 }; | |
253 | |
254 ///GSL_EUNIMPL = 24, /* requested feature not (yet) implemented */ | |
255 struct notImplemented : public error { | |
256 notImplemented() {}; | |
257 notImplemented(string r, string f, int l) : | |
258 error(r,f,l) {}; | |
259 }; | |
260 | |
261 ///GSL_ECACHE = 25, /* cache limit exceeded */ | |
262 struct cacheLimitExceeded : public error { | |
263 cacheLimitExceeded() {}; | |
264 cacheLimitExceeded(string r, string f, int l) : | |
265 error(r,f,l) {}; | |
266 }; | |
267 | |
268 ///GSL_ETABLE = 26, /* table limit exceeded */ | |
269 struct tableLimitExceeded : public error { | |
270 tableLimitExceeded() {}; | |
271 tableLimitExceeded(string r, string f, int l) : | |
272 error(r,f,l) {}; | |
273 }; | |
274 | |
275 ///GSL_ENOPROG = 27, /* iteration is not making progress towards solution */ | |
276 struct iterationNotProgressing : public error { | |
277 iterationNotProgressing() {}; | |
278 iterationNotProgressing(string r, string f, int l) : | |
279 error(r,f,l) {}; | |
280 }; | |
281 | |
282 ///GSL_ENOPROGJ = 28, /* jacobian evaluations are not improving solution */ | |
283 struct jacobiansNotImprovingSolution : public error { | |
284 jacobiansNotImprovingSolution() {}; | |
285 jacobiansNotImprovingSolution(string r, string f, int l) : | |
286 error(r,f,l) {}; | |
287 }; | |
288 | |
289 ///GSL_ETOLF = 29, /* cannot reach the specified tolerance in F */ | |
290 struct cannotReachToleranceInF : public error { | |
291 cannotReachToleranceInF() {}; | |
292 cannotReachToleranceInF(string r, string f, int l) : | |
293 error(r,f,l) {}; | |
294 }; | |
295 | |
296 ///GSL_ETOLX = 30, /* cannot reach the specified tolerance in X */ | |
297 struct cannotReachToleranceInX : public error { | |
298 cannotReachToleranceInX() {}; | |
299 cannotReachToleranceInX(string r, string f, int l) : | |
300 error(r,f,l) {}; | |
301 }; | |
302 | |
303 ///GSL_ETOLG = 31, /* cannot reach the specified tolerance in gradient */ | |
304 struct cannotReachToleranceInGradient : public error { | |
305 cannotReachToleranceInGradient() {}; | |
306 cannotReachToleranceInGradient(string r, string f, int l) : | |
307 error(r,f,l) {}; | |
308 }; | |
309 | |
310 ///GSL_EOF = 32 /* end of file */ | |
311 struct endOfFile : public error { | |
312 endOfFile() {}; | |
313 endOfFile(string r, string f, int l) : | |
314 error(r,f,l) {}; | |
315 }; | |
316 | |
317 ///Exception for indices out of range. | |
318 struct indexOutOfRange : public badArgument{ | |
319 size_t i,j,m,n; | |
320 indexOutOfRange() {}; | |
321 indexOutOfRange(string r, string f, int l) : | |
322 badArgument(r,f,l) {}; | |
323 }; | |
324 } | |
325 | |
12
6e06eb6ec448
Trivial change in include guards.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
4
diff
changeset
|
326 #endif //__ERROR_HPP__ |