00001
00002
00003
00004
00005 #ifndef BALL_COMMON_EXCEPTION_H
00006 #define BALL_COMMON_EXCEPTION_H
00007
00008 #ifndef BALL_CONFIG_CONFIG_H
00009 # include <BALL/CONFIG/config.h>
00010 #endif
00011
00012 #ifndef BALL_COMMON_GLOBAL_H
00013 # include <BALL/COMMON/global.h>
00014 #endif
00015
00016 #include <new>
00017 #include <string>
00018
00019 namespace BALL
00020 {
00021
00022 class String;
00023
00027 namespace Exception
00028 {
00029
00054 class BALL_EXPORT GeneralException
00055 : public std::exception
00056 {
00057 public:
00058
00062
00064 GeneralException();
00065
00067 GeneralException(const char* file, int line);
00068
00070 GeneralException
00071 (const char* file, int line,
00072 const String& name , const String& message);
00073
00075 GeneralException(const GeneralException& exception);
00076
00078 virtual ~GeneralException() throw();
00080
00084
00086 const char* getName() const;
00087
00089 const char* getMessage() const;
00090
00092 void setMessage(const std::string& message);
00093
00095 int getLine() const;
00096
00098 const char* getFile() const;
00100
00101 protected:
00102 const char* file_;
00103 int line_;
00104
00105 std::string name_;
00106 std::string message_;
00107 };
00108
00117 class BALL_EXPORT IndexUnderflow
00118 : public GeneralException
00119 {
00120 public:
00121
00122 IndexUnderflow(const char* file, int line, Index index = 0, Size size = 0);
00123
00124
00125 protected:
00126
00127 Size size_;
00128 Index index_;
00129 };
00130
00138 class BALL_EXPORT SizeUnderflow
00139 : public GeneralException
00140 {
00141 public:
00142
00143 SizeUnderflow(const char* file, int line, Size size = 0);
00144
00145 protected:
00146 Size size_;
00147 };
00148
00157 class BALL_EXPORT IndexOverflow
00158 : public GeneralException
00159 {
00160 public:
00161 IndexOverflow(const char* file, int line, Index index = 0, Size size = 0);
00162
00163 protected:
00164
00165 Size size_;
00166 Index index_;
00167 };
00168
00172 class BALL_EXPORT InvalidArgument
00173 : public GeneralException
00174 {
00175 public:
00176 InvalidArgument(const char* file, int line, const String& arg);
00177 };
00178
00182 class BALL_EXPORT InvalidRange
00183 : public GeneralException
00184 {
00185 public:
00186 InvalidRange(const char* file, int line, float value);
00187 };
00188
00189
00196 class BALL_EXPORT InvalidSize
00197 : public GeneralException
00198 {
00199 public:
00200
00201 InvalidSize(const char* file, int line, Size size = 0);
00202
00203 protected:
00204 Size size_;
00205 };
00206
00207
00212 class BALL_EXPORT OutOfRange
00213 : public GeneralException
00214 {
00215 public:
00216 OutOfRange(const char* file, int line);
00217 };
00218
00224 class BALL_EXPORT InvalidFormat
00225 : public GeneralException
00226 {
00227 public:
00228 InvalidFormat(const char* file, int line, const String& s);
00229
00230 ~InvalidFormat()
00231 throw();
00232
00233 protected:
00234
00235 std::string format_;
00236 };
00237
00243 class BALL_EXPORT IllegalSelfOperation
00244 : public GeneralException
00245 {
00246 public:
00247 IllegalSelfOperation(const char* file, int line);
00248 };
00249
00254 class BALL_EXPORT NullPointer
00255 : public GeneralException
00256 {
00257 public:
00258 NullPointer(const char* file, int line);
00259 };
00260
00264 class BALL_EXPORT InvalidIterator
00265 : public GeneralException
00266 {
00267 public:
00268 InvalidIterator(const char* file, int line);
00269 };
00270
00275 class BALL_EXPORT IncompatibleIterators
00276 : public GeneralException
00277 {
00278 public:
00279 IncompatibleIterators(const char* file, int line);
00280 };
00281
00288 class BALL_EXPORT NotImplemented
00289 : public GeneralException
00290 {
00291 public:
00292 NotImplemented(const char* file, int line);
00293 };
00294
00299 class BALL_EXPORT IllegalTreeOperation
00300 : public GeneralException
00301 {
00302 public:
00303 IllegalTreeOperation(const char* file, int line);
00304 };
00305
00312 class BALL_EXPORT OutOfMemory
00313 : public GeneralException, public std::bad_alloc
00314 {
00315 public:
00316 OutOfMemory(const char* file, int line, Size size = 0);
00317
00318 virtual ~OutOfMemory()
00319 throw();
00320
00321 protected:
00322 Size size_;
00323 };
00324
00327 class BALL_EXPORT BufferOverflow
00328 : public GeneralException
00329 {
00330 public:
00331 BufferOverflow(const char* file, int line);
00332 };
00333
00336 class BALL_EXPORT DivisionByZero
00337 : public GeneralException
00338 {
00339 public:
00340 DivisionByZero(const char* file, int line);
00341 };
00342
00345 class BALL_EXPORT OutOfGrid
00346 : public GeneralException
00347 {
00348 public:
00349 OutOfGrid(const char* file, int line);
00350 };
00351
00355 class BALL_EXPORT FileNotFound
00356 : public GeneralException
00357 {
00358 public:
00359 FileNotFound(const char* file, int line, const String& filename);
00360
00361 ~FileNotFound()
00362 throw();
00363 String getFilename() const;
00364
00365 protected:
00366 std::string filename_;
00367 };
00368
00372 class BALL_EXPORT IllegalPosition
00373 : public GeneralException
00374 {
00375 public:
00376 IllegalPosition(const char* file, int line, float x, float y, float z);
00377 };
00378
00382 class BALL_EXPORT ParseError
00383 : public GeneralException
00384 {
00385 public:
00387 ParseError(const char* file, int line, const String& expression,
00388 const String& message);
00389 };
00390
00394 class BALL_EXPORT Precondition
00395 : public GeneralException
00396 {
00397 public:
00399 Precondition(const char* file, int line, const char* condition);
00400 };
00401
00405 class BALL_EXPORT Postcondition
00406 : public GeneralException
00407 {
00408 public:
00410 Postcondition(const char* file, int line, const char* condition);
00411 };
00412
00414 class BALL_EXPORT InvalidOption: public Exception::GeneralException
00415 {
00416 public:
00417
00419 InvalidOption(const char* file, int line, String option);
00420 };
00421
00423 class BALL_EXPORT TooManyErrors
00424 : public Exception::GeneralException
00425 {
00426 public:
00428 TooManyErrors(const char* file, int line);
00429 };
00430
00432 class BALL_EXPORT TooManyBonds
00433 : public Exception::GeneralException
00434 {
00435 public:
00437 TooManyBonds(const char* file, int line, const String& error);
00438 };
00439
00443 class BALL_EXPORT CUDAError
00444 : public Exception::GeneralException
00445 {
00446 public:
00447 CUDAError(const char* file, int line, const String& error);
00448 };
00449
00457 class BALL_EXPORT NoBufferAvailable
00458 : public Exception::GeneralException
00459 {
00460 public:
00461 NoBufferAvailable(const char* file, int line, const String& reason);
00462 };
00463
00469 class BALL_EXPORT FormatUnsupported
00470 : public Exception::GeneralException
00471 {
00472 public:
00473 FormatUnsupported(const char* file, int line);
00474 };
00475
00478 class BALL_EXPORT GlobalExceptionHandler
00479 {
00480 public:
00484
00501 GlobalExceptionHandler();
00503
00507
00509 static void setName(const String& name);
00510
00512 static void setMessage(const String& message);
00513
00515 static void setLine(int line);
00516
00518 static void setFile(const String& file);
00519
00521 static void set
00522 (const String& file, int line,
00523 const String& name, const String& message);
00525
00526 protected:
00527
00529 static void terminate();
00530
00532 static void newHandler() throw(Exception::OutOfMemory);
00533
00534 static std::string file_;
00535 static int line_;
00536 static std::string name_;
00537 static std::string message_;
00538 };
00539
00542 BALL_EXPORT extern GlobalExceptionHandler globalHandler;
00543
00544 }
00563 BALL_EXPORT
00564 std::ostream& operator << (std::ostream& os, const Exception::GeneralException& e);
00565
00566 }
00567
00568 #endif // BALL_COMMON_EXCEPTION_H