Fawkes API  Fawkes Development Version
software.cpp
1 
2 /***************************************************************************
3  * software.cpp - basic software exceptions
4  *
5  * Created: Sun Oct 29 14:19:19 2006
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <core/exceptions/software.h>
25 
26 #include <cmath>
27 
28 namespace fawkes {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class NullPointerException <core/exceptions/software.h>
34  * A NULL pointer was supplied where not allowed.
35  * Throw this exception if a pointer to NULL has been supplied where this is
36  * not allowed.
37  * @ingroup Exceptions
38  */
39 /** Constructor
40  * @param format message format, takes sprintf() parameters as variadic arguments
41  */
42 NullPointerException::NullPointerException(const char *format, ...) throw()
43  : Exception()
44 {
45  va_list va;
46  va_start(va, format);
47  append_va(format, va);
48  va_end(va);
49 }
50 
51 
52 /** @class DivisionByZeroException <core/exceptions/software.h>
53  * Division by zero.
54  * Throw this if a division by zero has happened or is about to happen
55  * @ingroup Exceptions
56  */
57 /** Constructor
58  * @param format message format, takes sprintf() parameters as variadic arguments
59  */
60 DivisionByZeroException::DivisionByZeroException(const char *format, ...) throw()
61  : Exception()
62 {
63  va_list va;
64  va_start(va, format);
65  append_va(format, va);
66  va_end(va);
67 }
68 
69 
70 /** @class TypeMismatchException <core/exceptions/software.h>
71  * Type mismatch.
72  * Throw this exception if types of operations do not fit together.
73  * @ingroup Exceptions
74  */
75 /** Constructor
76  * @param format message format, takes sprintf() parameters as variadic arguments
77  */
78 TypeMismatchException::TypeMismatchException(const char *format, ...) throw()
79  : Exception()
80 {
81  va_list va;
82  va_start(va, format);
83  append_va(format, va);
84  va_end(va);
85 }
86 
87 
88 /** @class UnknownTypeException <core/exceptions/software.h>
89  * Unknown type.
90  * Throw this exception if you get an unknown type.
91  * @ingroup Exceptions
92  */
93 /** Constructor
94  * @param format message format, takes sprintf() parameters as variadic arguments
95  */
96 UnknownTypeException::UnknownTypeException(const char *format, ...) throw()
97  : Exception()
98 {
99  va_list va;
100  va_start(va, format);
101  append_va(format, va);
102  va_end(va);
103 }
104 
105 
106 /** @class DestructionInProgressException <core/exceptions/software.h>
107  * Delete in progress.
108  * Throw this exception if someone tried to access an object that is currently being
109  * destroyed.
110  * @ingroup Exceptions
111  */
112 /** Constructor
113  * @param format message format, takes sprintf() parameters as variadic arguments
114  */
116  : Exception()
117 {
118  va_list va;
119  va_start(va, format);
120  append_va(format, va);
121  va_end(va);
122 }
123 
124 
125 /** @class NotLockedException <core/exceptions/software.h>
126  * Operation on unlocked object.
127  * Throw this exception if someone tried to operate on an object with a method that needs
128  * outside locking. This can be detected utilizing Mutex::tryLock() in many situations.
129  * @ingroup Exceptions
130  */
131 /** Constructor.
132  * @param format message format, takes sprintf() parameters as variadic arguments
133  */
134 NotLockedException::NotLockedException(const char *format, ...) throw()
135  : Exception()
136 {
137  va_list va;
138  va_start(va, format);
139  append_va(format, va);
140  va_end(va);
141 }
142 
143 
144 /** @class NonPointerTypeExpectedException <core/exceptions/software.h>
145  * Non-pointer type expected.
146  * Throw this exception if you got a pointer type where you expected to get a non-pointer
147  * type variable.
148  * @ingroup Exceptions
149  */
150 /** Constructor.
151  * @param format message format, takes sprintf() parameters as variadic arguments
152  */
154  : Exception()
155 {
156  va_list va;
157  va_start(va, format);
158  append_va(format, va);
159  va_end(va);
160 }
161 
162 
163 /** @class MissingParameterException <core/exceptions/software.h>
164  * Expected parameter is missing.
165  * Throw this exception if you expected one or more parameters that have not been
166  * supplied.
167  * @ingroup Exceptions
168  */
169 /** Constructor.
170  * @param format message format, takes sprintf() parameters as variadic arguments
171  */
173  : Exception()
174 {
175  va_list va;
176  va_start(va, format);
177  append_va(format, va);
178  va_end(va);
179 }
180 
181 
182 /** @class IllegalArgumentException <core/exceptions/software.h>
183  * Expected parameter is missing.
184  * Throw this exception if you got a parameter that does not meet some kind of
185  * specification, i.e. it is of the wrong type or out of an allowed value range.
186  * @ingroup Exceptions
187  */
188 /** Constructor.
189  * @param format message format, takes sprintf() parameters as variadic arguments
190  */
192  : Exception()
193 {
194  va_list va;
195  va_start(va, format);
196  append_va(format, va);
197  va_end(va);
198 }
199 
200 
201 /** @class OutOfBoundsException >core/exceptions/software.h>
202  * Index out of bounds.
203  * Throw this exception if a value is out of bounds or if someone tries to access
204  * an iterator that is not in the allowed range.
205  * @ingroup Exceptions
206  */
207 
208 /** Constructor.
209  * @param msg informative message, appended to exception, base message is
210  * "Out Of Bounds"
211  */
213  : Exception("Out Of Bounds: %s", msg)
214 {
215 }
216 
217 /** Range constructor.
218  * Additionally to the message the ranges and actual values are added to the
219  * primary message.
220  * @param msg informative message
221  * @param val actual value
222  * @param min minimum required value
223  * @param max maximum allowed value
224  */
226  float min, float max) throw()
227  : Exception()
228 {
229  if ( (roundf(val) == val) && (roundf(min) == min) && (roundf(max) == max) ) {
230  // really the values are just integers
231  append("Out Of Bounds (%s): min: %.0f max: %.0f val: %.0f", msg, min, max, val);
232  } else {
233  // at least one "real" float
234  append("Out Of Bounds (%s): min: %f max: %f val: %f", msg, min, max, val);
235  }
236 }
237 
238 
239 /** @class AccessViolationException <core/exceptions/software.h>
240  * Access violates policy.
241  * Throw this exception if a any kind of access violates the policy, for example
242  * if someone tries to write to a read-only memory segment.
243  * @ingroup Exceptions
244  */
245 /** Constructor.
246  * @param format message format, takes sprintf() parameters as variadic arguments
247  */
249  : Exception()
250 {
251  va_list va;
252  va_start(va, format);
253  append_va(format, va);
254  va_end(va);
255 }
256 
257 
258 /** @class SyntaxErrorException <core/exceptions/software.h>
259  * Syntax error.
260  * Throw this exception if a syntax error happened, for example in interpreted
261  * code or a configuration file.
262  * @ingroup Exceptions
263  */
264 /** Constructor
265  * @param format message format, takes sprintf() parameters as variadic arguments
266  */
267 SyntaxErrorException::SyntaxErrorException(const char *format, ...) throw()
268  : Exception()
269 {
270  va_list va;
271  va_start(va, format);
272  append_va(format, va);
273  va_end(va);
274 }
275 
276 
277 /** @class NotImplementedException <core/exceptions/software.h>
278  * Called method has not been implemented.
279  * This exception is meant to be used in method stubs. Use this in base
280  * classes where methods are declared that may not be implemented by all
281  * and therefore making it pure virtual would just cause code clutter.
282  * @ingroup Exceptions
283  */
284 /** Constructor
285  * @param format message format, takes sprintf() parameters as variadic arguments
286  */
287 NotImplementedException::NotImplementedException(const char *format, ...) throw()
288  : Exception()
289 {
290  va_list va;
291  va_start(va, format);
292  append_va(format, va);
293  va_end(va);
294 }
295 
296 
297 } // end namespace fawkes
TypeMismatchException(const char *format,...)
Constructor.
Definition: software.cpp:78
NonPointerTypeExpectedException(const char *format,...)
Constructor.
Definition: software.cpp:153
NullPointerException(const char *format,...)
Constructor.
Definition: software.cpp:42
Fawkes library namespace.
Exception()
Constructor for subclasses.
Definition: exception.cpp:257
DestructionInProgressException(const char *format,...)
Constructor.
Definition: software.cpp:115
AccessViolationException(const char *format,...)
Constructor.
Definition: software.cpp:248
NotLockedException(const char *format,...)
Constructor.
Definition: software.cpp:134
SyntaxErrorException(const char *format,...)
Constructor.
Definition: software.cpp:267
Base class for exceptions in Fawkes.
Definition: exception.h:36
UnknownTypeException(const char *format,...)
Constructor.
Definition: software.cpp:96
IllegalArgumentException(const char *format,...)
Constructor.
Definition: software.cpp:191
OutOfBoundsException(const char *msg)
Constructor.
Definition: software.cpp:212
void append_va(const char *format, va_list va)
Append messages to the message list.
Definition: exception.cpp:361
NotImplementedException(const char *format,...)
Constructor.
Definition: software.cpp:287
DivisionByZeroException(const char *format,...)
Constructor.
Definition: software.cpp:60
void append(const char *format,...)
Append messages to the message list.
Definition: exception.cpp:341
MissingParameterException(const char *format,...)
Constructor.
Definition: software.cpp:172