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, ...) noexcept : 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, ...) noexcept : 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, ...) noexcept : 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, ...) noexcept : 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, ...) noexcept : 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  */
207  float val,
208  float min,
209  float max) noexcept
210 : Exception()
211 {
212  if ((roundf(val) == val) && (roundf(min) == min) && (roundf(max) == max)) {
213  // really the values are just integers
214  append("Out Of Bounds (%s): min: %.0f max: %.0f val: %.0f", msg, min, max, val);
215  } else {
216  // at least one "real" float
217  append("Out Of Bounds (%s): min: %f max: %f val: %f", msg, min, max, val);
218  }
219 }
220 
221 /** @class AccessViolationException <core/exceptions/software.h>
222  * Access violates policy.
223  * Throw this exception if a any kind of access violates the policy, for example
224  * if someone tries to write to a read-only memory segment.
225  * @ingroup Exceptions
226  */
227 /** Constructor.
228  * @param format message format, takes sprintf() parameters as variadic arguments
229  */
231 {
232  va_list va;
233  va_start(va, format);
234  append_va(format, va);
235  va_end(va);
236 }
237 
238 /** @class SyntaxErrorException <core/exceptions/software.h>
239  * Syntax error.
240  * Throw this exception if a syntax error happened, for example in interpreted
241  * code or a configuration file.
242  * @ingroup Exceptions
243  */
244 /** Constructor
245  * @param format message format, takes sprintf() parameters as variadic arguments
246  */
247 SyntaxErrorException::SyntaxErrorException(const char *format, ...) noexcept : Exception()
248 {
249  va_list va;
250  va_start(va, format);
251  append_va(format, va);
252  va_end(va);
253 }
254 
255 /** @class NotImplementedException <core/exceptions/software.h>
256  * Called method has not been implemented.
257  * This exception is meant to be used in method stubs. Use this in base
258  * classes where methods are declared that may not be implemented by all
259  * and therefore making it pure virtual would just cause code clutter.
260  * @ingroup Exceptions
261  */
262 /** Constructor
263  * @param format message format, takes sprintf() parameters as variadic arguments
264  */
265 NotImplementedException::NotImplementedException(const char *format, ...) noexcept : Exception()
266 {
267  va_list va;
268  va_start(va, format);
269  append_va(format, va);
270  va_end(va);
271 }
272 
273 } // end namespace fawkes
AccessViolationException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:230
DestructionInProgressException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:104
DivisionByZeroException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:55
Base class for exceptions in Fawkes.
Definition: exception.h:36
void append_va(const char *format, va_list va) noexcept
Append messages to the message list.
Definition: exception.cpp:353
IllegalArgumentException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:174
MissingParameterException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:157
NonPointerTypeExpectedException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:139
NotImplementedException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:265
NotLockedException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:122
NullPointerException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:39
OutOfBoundsException(const char *msg) noexcept
Constructor.
Definition: software.cpp:193
SyntaxErrorException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:247
TypeMismatchException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:71
UnknownTypeException(const char *format,...) noexcept
Constructor.
Definition: software.cpp:87
Fawkes library namespace.