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 
30 /** @class NullPointerException <core/exceptions/software.h>
31  * A NULL pointer was supplied where not allowed.
32  * Throw this exception if a pointer to NULL has been supplied where this is
33  * not allowed.
34  * @ingroup Exceptions
35  */
36 /** Constructor
37  * @param format message format, takes sprintf() parameters as variadic arguments
38  */
39 NullPointerException::NullPointerException(const char *format, ...) throw() : Exception()
40 {
41  va_list va;
42  va_start(va, format);
43  append_va(format, va);
44  va_end(va);
45 }
46 
47 /** @class DivisionByZeroException <core/exceptions/software.h>
48  * Division by zero.
49  * Throw this if a division by zero has happened or is about to happen
50  * @ingroup Exceptions
51  */
52 /** Constructor
53  * @param format message format, takes sprintf() parameters as variadic arguments
54  */
55 DivisionByZeroException::DivisionByZeroException(const char *format, ...) throw() : Exception()
56 {
57  va_list va;
58  va_start(va, format);
59  append_va(format, va);
60  va_end(va);
61 }
62 
63 /** @class TypeMismatchException <core/exceptions/software.h>
64  * Type mismatch.
65  * Throw this exception if types of operations do not fit together.
66  * @ingroup Exceptions
67  */
68 /** Constructor
69  * @param format message format, takes sprintf() parameters as variadic arguments
70  */
71 TypeMismatchException::TypeMismatchException(const char *format, ...) throw() : Exception()
72 {
73  va_list va;
74  va_start(va, format);
75  append_va(format, va);
76  va_end(va);
77 }
78 
79 /** @class UnknownTypeException <core/exceptions/software.h>
80  * Unknown type.
81  * Throw this exception if you get an unknown type.
82  * @ingroup Exceptions
83  */
84 /** Constructor
85  * @param format message format, takes sprintf() parameters as variadic arguments
86  */
87 UnknownTypeException::UnknownTypeException(const char *format, ...) throw() : Exception()
88 {
89  va_list va;
90  va_start(va, format);
91  append_va(format, va);
92  va_end(va);
93 }
94 
95 /** @class DestructionInProgressException <core/exceptions/software.h>
96  * Delete in progress.
97  * Throw this exception if someone tried to access an object that is currently being
98  * destroyed.
99  * @ingroup Exceptions
100  */
101 /** Constructor
102  * @param format message format, takes sprintf() parameters as variadic arguments
103  */
105 : Exception()
106 {
107  va_list va;
108  va_start(va, format);
109  append_va(format, va);
110  va_end(va);
111 }
112 
113 /** @class NotLockedException <core/exceptions/software.h>
114  * Operation on unlocked object.
115  * Throw this exception if someone tried to operate on an object with a method that needs
116  * outside locking. This can be detected utilizing Mutex::tryLock() in many situations.
117  * @ingroup Exceptions
118  */
119 /** Constructor.
120  * @param format message format, takes sprintf() parameters as variadic arguments
121  */
122 NotLockedException::NotLockedException(const char *format, ...) throw() : Exception()
123 {
124  va_list va;
125  va_start(va, format);
126  append_va(format, va);
127  va_end(va);
128 }
129 
130 /** @class NonPointerTypeExpectedException <core/exceptions/software.h>
131  * Non-pointer type expected.
132  * Throw this exception if you got a pointer type where you expected to get a non-pointer
133  * type variable.
134  * @ingroup Exceptions
135  */
136 /** Constructor.
137  * @param format message format, takes sprintf() parameters as variadic arguments
138  */
140 : Exception()
141 {
142  va_list va;
143  va_start(va, format);
144  append_va(format, va);
145  va_end(va);
146 }
147 
148 /** @class MissingParameterException <core/exceptions/software.h>
149  * Expected parameter is missing.
150  * Throw this exception if you expected one or more parameters that have not been
151  * supplied.
152  * @ingroup Exceptions
153  */
154 /** Constructor.
155  * @param format message format, takes sprintf() parameters as variadic arguments
156  */
158 {
159  va_list va;
160  va_start(va, format);
161  append_va(format, va);
162  va_end(va);
163 }
164 
165 /** @class IllegalArgumentException <core/exceptions/software.h>
166  * Expected parameter is missing.
167  * Throw this exception if you got a parameter that does not meet some kind of
168  * specification, i.e. it is of the wrong type or out of an allowed value range.
169  * @ingroup Exceptions
170  */
171 /** Constructor.
172  * @param format message format, takes sprintf() parameters as variadic arguments
173  */
175 {
176  va_list va;
177  va_start(va, format);
178  append_va(format, va);
179  va_end(va);
180 }
181 
182 /** @class OutOfBoundsException >core/exceptions/software.h>
183  * Index out of bounds.
184  * Throw this exception if a value is out of bounds or if someone tries to access
185  * an iterator that is not in the allowed range.
186  * @ingroup Exceptions
187  */
188 
189 /** Constructor.
190  * @param msg informative message, appended to exception, base message is
191  * "Out Of Bounds"
192  */
194 : Exception("Out Of Bounds: %s", msg)
195 {
196 }
197 
198 /** Range constructor.
199  * Additionally to the message the ranges and actual values are added to the
200  * primary message.
201  * @param msg informative message
202  * @param val actual value
203  * @param min minimum required value
204  * @param max maximum allowed value
205  */
206 OutOfBoundsException::OutOfBoundsException(const char *msg, float val, float min, float max) throw()
207 : Exception()
208 {
209  if ((roundf(val) == val) && (roundf(min) == min) && (roundf(max) == max)) {
210  // really the values are just integers
211  append("Out Of Bounds (%s): min: %.0f max: %.0f val: %.0f", msg, min, max, val);
212  } else {
213  // at least one "real" float
214  append("Out Of Bounds (%s): min: %f max: %f val: %f", msg, min, max, val);
215  }
216 }
217 
218 /** @class AccessViolationException <core/exceptions/software.h>
219  * Access violates policy.
220  * Throw this exception if a any kind of access violates the policy, for example
221  * if someone tries to write to a read-only memory segment.
222  * @ingroup Exceptions
223  */
224 /** Constructor.
225  * @param format message format, takes sprintf() parameters as variadic arguments
226  */
228 {
229  va_list va;
230  va_start(va, format);
231  append_va(format, va);
232  va_end(va);
233 }
234 
235 /** @class SyntaxErrorException <core/exceptions/software.h>
236  * Syntax error.
237  * Throw this exception if a syntax error happened, for example in interpreted
238  * code or a configuration file.
239  * @ingroup Exceptions
240  */
241 /** Constructor
242  * @param format message format, takes sprintf() parameters as variadic arguments
243  */
244 SyntaxErrorException::SyntaxErrorException(const char *format, ...) throw() : Exception()
245 {
246  va_list va;
247  va_start(va, format);
248  append_va(format, va);
249  va_end(va);
250 }
251 
252 /** @class NotImplementedException <core/exceptions/software.h>
253  * Called method has not been implemented.
254  * This exception is meant to be used in method stubs. Use this in base
255  * classes where methods are declared that may not be implemented by all
256  * and therefore making it pure virtual would just cause code clutter.
257  * @ingroup Exceptions
258  */
259 /** Constructor
260  * @param format message format, takes sprintf() parameters as variadic arguments
261  */
263 {
264  va_list va;
265  va_start(va, format);
266  append_va(format, va);
267  va_end(va);
268 }
269 
270 } // end namespace fawkes
fawkes::OutOfBoundsException::OutOfBoundsException
OutOfBoundsException(const char *msg)
Constructor.
Definition: software.cpp:193
fawkes::DivisionByZeroException::DivisionByZeroException
DivisionByZeroException(const char *format,...)
Constructor.
Definition: software.cpp:55
fawkes::Exception::append_va
void append_va(const char *format, va_list va)
Append messages to the message list.
Definition: exception.cpp:353
fawkes::NullPointerException::NullPointerException
NullPointerException(const char *format,...)
Constructor.
Definition: software.cpp:39
fawkes::SyntaxErrorException::SyntaxErrorException
SyntaxErrorException(const char *format,...)
Constructor.
Definition: software.cpp:244
fawkes::AccessViolationException::AccessViolationException
AccessViolationException(const char *format,...)
Constructor.
Definition: software.cpp:227
fawkes::TypeMismatchException::TypeMismatchException
TypeMismatchException(const char *format,...)
Constructor.
Definition: software.cpp:71
fawkes
Fawkes library namespace.
fawkes::NotImplementedException::NotImplementedException
NotImplementedException(const char *format,...)
Constructor.
Definition: software.cpp:262
fawkes::IllegalArgumentException::IllegalArgumentException
IllegalArgumentException(const char *format,...)
Constructor.
Definition: software.cpp:174
fawkes::UnknownTypeException::UnknownTypeException
UnknownTypeException(const char *format,...)
Constructor.
Definition: software.cpp:87
fawkes::MissingParameterException::MissingParameterException
MissingParameterException(const char *format,...)
Constructor.
Definition: software.cpp:157
fawkes::NotLockedException::NotLockedException
NotLockedException(const char *format,...)
Constructor.
Definition: software.cpp:122
fawkes::NonPointerTypeExpectedException::NonPointerTypeExpectedException
NonPointerTypeExpectedException(const char *format,...)
Constructor.
Definition: software.cpp:139
fawkes::DestructionInProgressException::DestructionInProgressException
DestructionInProgressException(const char *format,...)
Constructor.
Definition: software.cpp:104
fawkes::Exception
Base class for exceptions in Fawkes.
Definition: exception.h:36