Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * software.cpp - basic software exceptions 00004 * 00005 * Created: Sun Oct 29 14:19:19 2006 00006 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <core/exceptions/software.h> 00025 00026 #include <cmath> 00027 00028 namespace fawkes { 00029 #if 0 /* just to make Emacs auto-indent happy */ 00030 } 00031 #endif 00032 00033 /** @class NullPointerException <core/exceptions/software.h> 00034 * A NULL pointer was supplied where not allowed. 00035 * Throw this exception if a pointer to NULL has been supplied where this is 00036 * not allowed. 00037 * @ingroup Exceptions 00038 */ 00039 /** Constructor 00040 * @param format message format, takes sprintf() parameters as variadic arguments 00041 */ 00042 NullPointerException::NullPointerException(const char *format, ...) throw() 00043 : Exception() 00044 { 00045 va_list va; 00046 va_start(va, format); 00047 append_va(format, va); 00048 va_end(va); 00049 } 00050 00051 00052 /** @class DivisionByZeroException <core/exceptions/software.h> 00053 * Division by zero. 00054 * Throw this if a division by zero has happened or is about to happen 00055 * @ingroup Exceptions 00056 */ 00057 /** Constructor 00058 * @param format message format, takes sprintf() parameters as variadic arguments 00059 */ 00060 DivisionByZeroException::DivisionByZeroException(const char *format, ...) throw() 00061 : Exception() 00062 { 00063 va_list va; 00064 va_start(va, format); 00065 append_va(format, va); 00066 va_end(va); 00067 } 00068 00069 00070 /** @class TypeMismatchException <core/exceptions/software.h> 00071 * Type mismatch. 00072 * Throw this exception if types of operations do not fit together. 00073 * @ingroup Exceptions 00074 */ 00075 /** Constructor 00076 * @param format message format, takes sprintf() parameters as variadic arguments 00077 */ 00078 TypeMismatchException::TypeMismatchException(const char *format, ...) throw() 00079 : Exception() 00080 { 00081 va_list va; 00082 va_start(va, format); 00083 append_va(format, va); 00084 va_end(va); 00085 } 00086 00087 00088 /** @class UnknownTypeException <core/exceptions/software.h> 00089 * Unknown type. 00090 * Throw this exception if you get an unknown type. 00091 * @ingroup Exceptions 00092 */ 00093 /** Constructor 00094 * @param format message format, takes sprintf() parameters as variadic arguments 00095 */ 00096 UnknownTypeException::UnknownTypeException(const char *format, ...) throw() 00097 : Exception() 00098 { 00099 va_list va; 00100 va_start(va, format); 00101 append_va(format, va); 00102 va_end(va); 00103 } 00104 00105 00106 /** @class DestructionInProgressException <core/exceptions/software.h> 00107 * Delete in progress. 00108 * Throw this exception if someone tried to access an object that is currently being 00109 * destroyed. 00110 * @ingroup Exceptions 00111 */ 00112 /** Constructor 00113 * @param format message format, takes sprintf() parameters as variadic arguments 00114 */ 00115 DestructionInProgressException::DestructionInProgressException(const char *format, ...) throw() 00116 : Exception() 00117 { 00118 va_list va; 00119 va_start(va, format); 00120 append_va(format, va); 00121 va_end(va); 00122 } 00123 00124 00125 /** @class NotLockedException <core/exceptions/software.h> 00126 * Operation on unlocked object. 00127 * Throw this exception if someone tried to operate on an object with a method that needs 00128 * outside locking. This can be detected utilizing Mutex::tryLock() in many situations. 00129 * @ingroup Exceptions 00130 */ 00131 /** Constructor. 00132 * @param format message format, takes sprintf() parameters as variadic arguments 00133 */ 00134 NotLockedException::NotLockedException(const char *format, ...) throw() 00135 : Exception() 00136 { 00137 va_list va; 00138 va_start(va, format); 00139 append_va(format, va); 00140 va_end(va); 00141 } 00142 00143 00144 /** @class NonPointerTypeExpectedException <core/exceptions/software.h> 00145 * Non-pointer type expected. 00146 * Throw this exception if you got a pointer type where you expected to get a non-pointer 00147 * type variable. 00148 * @ingroup Exceptions 00149 */ 00150 /** Constructor. 00151 * @param format message format, takes sprintf() parameters as variadic arguments 00152 */ 00153 NonPointerTypeExpectedException::NonPointerTypeExpectedException(const char *format, ...) throw() 00154 : Exception() 00155 { 00156 va_list va; 00157 va_start(va, format); 00158 append_va(format, va); 00159 va_end(va); 00160 } 00161 00162 00163 /** @class MissingParameterException <core/exceptions/software.h> 00164 * Expected parameter is missing. 00165 * Throw this exception if you expected one or more parameters that have not been 00166 * supplied. 00167 * @ingroup Exceptions 00168 */ 00169 /** Constructor. 00170 * @param format message format, takes sprintf() parameters as variadic arguments 00171 */ 00172 MissingParameterException::MissingParameterException(const char *format, ...) throw() 00173 : Exception() 00174 { 00175 va_list va; 00176 va_start(va, format); 00177 append_va(format, va); 00178 va_end(va); 00179 } 00180 00181 00182 /** @class IllegalArgumentException <core/exceptions/software.h> 00183 * Expected parameter is missing. 00184 * Throw this exception if you got a parameter that does not meet some kind of 00185 * specification, i.e. it is of the wrong type or out of an allowed value range. 00186 * @ingroup Exceptions 00187 */ 00188 /** Constructor. 00189 * @param format message format, takes sprintf() parameters as variadic arguments 00190 */ 00191 IllegalArgumentException::IllegalArgumentException(const char *format, ...) throw() 00192 : Exception() 00193 { 00194 va_list va; 00195 va_start(va, format); 00196 append_va(format, va); 00197 va_end(va); 00198 } 00199 00200 00201 /** @class OutOfBoundsException >core/exceptions/software.h> 00202 * Index out of bounds. 00203 * Throw this exception if a value is out of bounds or if someone tries to access 00204 * an iterator that is not in the allowed range. 00205 * @ingroup Exceptions 00206 */ 00207 00208 /** Constructor. 00209 * @param msg informative message, appended to exception, base message is 00210 * "Out Of Bounds" 00211 */ 00212 OutOfBoundsException::OutOfBoundsException(const char *msg) throw() 00213 : Exception("Out Of Bounds: %s", msg) 00214 { 00215 } 00216 00217 /** Range constructor. 00218 * Additionally to the message the ranges and actual values are added to the 00219 * primary message. 00220 * @param msg informative message 00221 * @param val actual value 00222 * @param min minimum required value 00223 * @param max maximum allowed value 00224 */ 00225 OutOfBoundsException::OutOfBoundsException(const char *msg, float val, 00226 float min, float max) throw() 00227 : Exception() 00228 { 00229 if ( (roundf(val) == val) && (roundf(min) == min) && (roundf(max) == max) ) { 00230 // really the values are just integers 00231 append("Out Of Bounds (%s): min: %.0f max: %.0f val: %.0f", msg, min, max, val); 00232 } else { 00233 // at least one "real" float 00234 append("Out Of Bounds (%s): min: %f max: %f val: %f", msg, min, max, val); 00235 } 00236 } 00237 00238 00239 /** @class AccessViolationException <core/exceptions/software.h> 00240 * Access violates policy. 00241 * Throw this exception if a any kind of access violates the policy, for example 00242 * if someone tries to write to a read-only memory segment. 00243 * @ingroup Exceptions 00244 */ 00245 /** Constructor. 00246 * @param format message format, takes sprintf() parameters as variadic arguments 00247 */ 00248 AccessViolationException::AccessViolationException(const char *format, ...) throw() 00249 : Exception() 00250 { 00251 va_list va; 00252 va_start(va, format); 00253 append_va(format, va); 00254 va_end(va); 00255 } 00256 00257 00258 /** @class SyntaxErrorException <core/exceptions/software.h> 00259 * Syntax error. 00260 * Throw this exception if a syntax error happened, for example in interpreted 00261 * code or a configuration file. 00262 * @ingroup Exceptions 00263 */ 00264 /** Constructor 00265 * @param format message format, takes sprintf() parameters as variadic arguments 00266 */ 00267 SyntaxErrorException::SyntaxErrorException(const char *format, ...) throw() 00268 : Exception() 00269 { 00270 va_list va; 00271 va_start(va, format); 00272 append_va(format, va); 00273 va_end(va); 00274 } 00275 00276 00277 /** @class NotImplementedException <core/exceptions/software.h> 00278 * Called method has not been implemented. 00279 * This exception is meant to be used in method stubs. Use this in base 00280 * classes where methods are declared that may not be implemented by all 00281 * and therefore making it pure virtual would just cause code clutter. 00282 * @ingroup Exceptions 00283 */ 00284 /** Constructor 00285 * @param format message format, takes sprintf() parameters as variadic arguments 00286 */ 00287 NotImplementedException::NotImplementedException(const char *format, ...) throw() 00288 : Exception() 00289 { 00290 va_list va; 00291 va_start(va, format); 00292 append_va(format, va); 00293 va_end(va); 00294 } 00295 00296 00297 } // end namespace fawkes