00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __TOOLBOX_EXCEPTION_H
00010 #define __TOOLBOX_EXCEPTION_H
00011
00012
00018 #define NEW_EASSERTIONFAILED(message) (new EAssertionFailed(message, __FILE__, __LINE__))
00019
00025 #define NEW_EDEVICEERROR(message) (new EDeviceError(message, __FILE__, __LINE__))
00026
00027 #ifdef _WINDOWS
00028
00034 #define NEW_EDEVICEERROR_RESULT(message, result) \
00035 (EDeviceError::CreateDeviceError((message), (result), __FILE__, __LINE__))
00036 #endif
00037
00043 #define NEW_EILLEGALARGUMENT(message) (new EIllegalArgument(message, __FILE__, __LINE__))
00044
00050 #define NEW_EILLEGALSTATE(message) (new EIllegalState(message, __FILE__, __LINE__))
00051
00057 #define NEW_EINDEXOUTOFBOUNDS(message) (new EIndexOutOfBounds(message, __FILE__, __LINE__))
00058
00064 #define NEW_EINTERNALERROR(message) (new EInternalError(message, __FILE__, __LINE__))
00065
00071 #define NEW_EIOERROR(message) (new EIOError(message, __FILE__, __LINE__))
00072
00078 #define NEW_ENOSUCHELEMENT(message) (new ENoSuchElement(message, __FILE__, __LINE__))
00079
00085 #define NEW_ENOTSUPPORTED(message) (new ENotSupported(message, __FILE__, __LINE__))
00086
00092 #define NEW_ENULLPOINTER(message) (new ENullPointer(message, __FILE__, __LINE__))
00093
00094
00095 #ifdef _DEBUG
00096
00104 #define ASSERTION(assertion) \
00105 (EAssertionFailed::Assertion((assertion), #assertion, __FILE__, __LINE__))
00106 #else
00107
00111 #define ASSERTION(assertion) (((0)))
00112 #endif
00113
00114 #ifdef _DEBUG
00115
00123 #define ASSERTION_POINTER(pointer) \
00124 (ENullPointer::AssertionValid((pointer), #pointer##" is null", __FILE__, __LINE__))
00125 #else
00126
00130 #define ASSERTION_POINTER(pointer) (((0)))
00131 #endif
00132
00133 #ifdef _DEBUG
00134
00142 #define ASSERTION_THIS \
00143 (ENullPointer::AssertionValid((this), "this is null", __FILE__, __LINE__))
00144 #else
00145
00149 #define ASSERTION_THIS (((0)))
00150 #endif
00151
00152
00153 namespace toolbox
00154 {
00165 class Exception
00166 {
00167 protected:
00168
00172 const char * ClassName;
00173
00178 long LineNumber;
00179
00183 char * Message;
00184
00189 char * Source;
00190
00200 Exception(const char * className, const char * message, const char * source, long lineNumber);
00201
00206 void SetMessage(const char * message);
00207
00212 void SetSource(const char * source);
00213
00214 public:
00215
00219 virtual ~Exception();
00220
00225 inline const char * GetClassName();
00226
00231 inline const char * GetMessage();
00232
00237 inline long GetLineNumber();
00238
00243 inline const char * GetSource();
00244 };
00245
00251 class EAutoBreaking : public Exception
00252 {
00253 protected:
00254
00264 EAutoBreaking(const char * className, const char * message, const char * source, long lineNumber);
00265 };
00266
00275 class EAssertionFailed : public EAutoBreaking
00276 {
00277 private:
00278
00287 EAssertionFailed(const char * message, const char * source, long lineNumber);
00288
00289 public:
00290
00301 static void Assertion(bool assertion, const char * message,
00302 const char * source, long lineNumber);
00303
00313 static void Assertion(bool assertion, const char * source, long lineNumber);
00314 };
00315
00321 class EDeviceError : public EAutoBreaking
00322 {
00323 public:
00324
00334 EDeviceError(const char * message, const char * source, long lineNumber);
00335
00348 #ifdef _WINDOWS
00349 static EDeviceError * CreateDeviceError(const char * message,
00350 HRESULT result, const char * source, long lineNumber);
00351
00358 static String GetErrorMessage(HRESULT result);
00359
00364 static inline String GetLastErrorMessage();
00365 #endif
00366 };
00367
00373 class EIllegalArgument : public EAutoBreaking
00374 {
00375 public:
00376
00386 EIllegalArgument(const char * message, const char * source, long lineNumber);
00387 };
00388
00395 class EIllegalState : public EAutoBreaking
00396 {
00397 public:
00398
00408 EIllegalState(const char * message, const char * source, long lineNumber);
00409 };
00410
00417 class EIndexOutOfBounds : public EAutoBreaking
00418 {
00419 public:
00420
00430 EIndexOutOfBounds(const char * message, const char * source, long lineNumber);
00431 };
00432
00439 class EInternalError : public EAutoBreaking
00440 {
00441 public:
00442
00452 EInternalError(const char * message, const char * source, long lineNumber);
00453 };
00454
00461 class EIOError : public EAutoBreaking
00462 {
00463 public:
00464
00474 EIOError(const char * message, const char * source, long lineNumber);
00475 };
00476
00482 class ENoSuchElement : public EAutoBreaking
00483 {
00484 public:
00485
00495 ENoSuchElement(const char * message, const char * source, long lineNumber);
00496 };
00497
00503 class ENotSupported : public EAutoBreaking
00504 {
00505 public:
00506
00516 ENotSupported(const char * message, const char * source, long lineNumber);
00517 };
00518
00525 class ENullPointer : public EAutoBreaking
00526 {
00527 private:
00528
00537 ENullPointer(const char * message, const char * source, long lineNumber);
00538
00539 public:
00540
00551 static void AssertionValid(const void * pointer, const char * message,
00552 const char * source, long lineNumber);
00553
00563 static void AssertionValid(const void * pointer, const char * source, long lineNumber);
00564 };
00565
00571 class EOutOfMemory : public Exception
00572 {
00573 private:
00574
00580 static EOutOfMemory Singleton;
00581
00588 EOutOfMemory();
00589
00590 public:
00591
00598 static inline EOutOfMemory * Get();
00599 };
00600 }
00601
00602
00603 #endif