00001 // -*- C++ -*- 00002 // 00003 // Copyright (c) 2006 by Rafael Ostertag 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // 00020 // $Id: casexception.h,v 1.14 2006/12/28 19:01:24 rafi Exp $ 00021 // 00022 00046 #ifndef _CASEXCEPTION_H 00047 #define _CASEXCEPTION_H 00048 00049 #ifdef HAVE_CONFIG_H 00050 #include "config.h" 00051 #endif 00052 00053 #include <pthread.h> 00054 00055 #include <string> 00056 #include <exception> 00057 00058 #include <cstdio> 00059 #include <cstring> 00060 00070 class CASException : public std::exception { 00071 protected: 00078 std::string msg; 00079 00080 public: 00086 CASException() throw () {} 00087 00097 const char* what() const throw() { return msg.c_str(); } 00098 00104 ~CASException() throw() {} 00105 }; 00106 00107 00113 class EInternal : public CASException { 00114 public: 00120 EInternal() throw () { 00121 msg = "Internal error occured"; 00122 } 00123 00129 ~EInternal() throw() {} 00130 }; 00131 00132 00138 class EInvArg : public CASException { 00139 public: 00145 EInvArg() throw () { 00146 msg = "Invalid argument"; 00147 } 00148 00154 ~EInvArg() throw() {} 00155 }; 00156 00157 00166 class EUninitializedPtr : public CASException { 00167 public: 00173 EUninitializedPtr() throw () { 00174 msg = "Uninitialized pointer encountered"; 00175 } 00176 00182 ~EUninitializedPtr() throw() {} 00183 }; 00184 00192 class EDoesNotApply : public CASException { 00193 public: 00199 inline EDoesNotApply() throw () { 00200 msg = "Method does not apply to this object"; 00201 } 00202 00211 inline EDoesNotApply ( std::string &m ) throw() { 00212 msg = m; 00213 } 00214 00220 ~EDoesNotApply() throw() {} 00221 }; 00222 00230 class EEvaluateFirst : public CASException { 00231 public: 00237 inline EEvaluateFirst() throw () { 00238 msg = "Method expects evaluated object"; 00239 } 00248 inline EEvaluateFirst ( std::string &m ) throw() { 00249 msg = m; 00250 } 00251 00257 ~EEvaluateFirst() throw() {} 00258 }; 00259 00260 00266 class ENullPtr : public CASException { 00267 public: 00273 ENullPtr() throw () { 00274 msg = "Null pointer encountered"; 00275 } 00276 00282 ~ENullPtr() throw() {} 00283 }; 00284 00285 00292 class EBufTooSmall : public CASException { 00293 public: 00299 EBufTooSmall() throw () { 00300 msg = "Buffer too small"; 00301 } 00302 00308 ~EBufTooSmall() throw() {} 00309 }; 00310 00316 class EDivByZero : public CASException { 00317 public: 00323 EDivByZero() throw () { 00324 msg = "Division by zero"; 00325 } 00326 00332 ~EDivByZero() throw() {} 00333 }; 00334 00335 00341 class ENotImplemented : public CASException { 00342 public: 00348 ENotImplemented() throw () { 00349 msg = "Method not implemented"; 00350 } 00351 00357 ~ENotImplemented() throw() {} 00358 }; 00359 00360 00367 class ECASGarbageThread_EAGAIN : public CASException { 00368 public: 00377 ECASGarbageThread_EAGAIN ( std::string &func_name ) throw () { 00378 msg = func_name + ": Too many threads."; 00379 } 00380 00386 ~ECASGarbageThread_EAGAIN() throw() {} 00387 }; 00388 00389 00397 class ECASGarbageThread_UNKNOWN : public CASException { 00398 public: 00407 ECASGarbageThread_UNKNOWN ( std::string &func_name ) throw () { 00408 msg = func_name + ": Unknown error"; 00409 } 00410 00416 ~ECASGarbageThread_UNKNOWN() throw() {} 00417 }; 00418 00424 class ECASGarbageThread_EDEADLK : public CASException { 00425 public: 00434 ECASGarbageThread_EDEADLK ( std::string &func_name ) throw () { 00435 msg = func_name + ": Dead lock"; 00436 } 00437 00443 ~ECASGarbageThread_EDEADLK() throw() {} 00444 }; 00445 00446 00452 class ECASGarbageThread_ENOMEM : public CASException { 00453 public: 00462 ECASGarbageThread_ENOMEM ( std::string &func_name ) throw () { 00463 msg = func_name + ": No memory"; 00464 } 00465 00471 ~ECASGarbageThread_ENOMEM() throw() {} 00472 }; 00473 00474 00480 class ECASGarbageThread_ESRCH : public CASException { 00481 public: 00491 ECASGarbageThread_ESRCH ( std::string &func_name, pthread_t tid ) throw () { 00492 char tmp[30]; 00493 snprintf ( tmp, 30, "%ul", ( unsigned int ) tid ); 00494 msg = func_name + ": Could not find thread #" + tmp; 00495 } 00496 00502 ~ECASGarbageThread_ESRCH() throw() {} 00503 }; 00504 00505 00512 class ECASGarbageThread_EINVAL : public CASException { 00513 public: 00523 ECASGarbageThread_EINVAL ( std::string &func_name ) throw () { 00524 msg = func_name + ": Invalid argument"; 00525 } 00526 00532 ~ECASGarbageThread_EINVAL() throw() {} 00533 }; 00534 00535 00547 inline void checkptr ( const void *ptr ) { 00548 if ( ptr == 0 ) { 00549 throw ENullPtr(); 00550 } 00551 } 00552 00557 #endif /* _CASEXCEPTION_H */
1.4.7