diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2006-07-26 19:16:58 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2006-07-26 19:16:58 +0000 |
| commit | 579c3ac445043122b0a702bdb2542d9ea404b62e (patch) | |
| tree | a96017529296f52a357e25de37b8c4cd052bebf5 /src/exceptionbase.h | |
| parent | 9e27762c2b4c1baf5b2aff003fbc56236fd742e6 (diff) | |
| download | libbu++-579c3ac445043122b0a702bdb2542d9ea404b62e.tar.gz libbu++-579c3ac445043122b0a702bdb2542d9ea404b62e.tar.bz2 libbu++-579c3ac445043122b0a702bdb2542d9ea404b62e.tar.xz libbu++-579c3ac445043122b0a702bdb2542d9ea404b62e.zip | |
Exceptions have been re-worked, and are easier to use, and don't collide with
system includues anymore.
Diffstat (limited to 'src/exceptionbase.h')
| -rw-r--r-- | src/exceptionbase.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/exceptionbase.h b/src/exceptionbase.h new file mode 100644 index 0000000..c0ced37 --- /dev/null +++ b/src/exceptionbase.h | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | #ifndef EXCEPTION_BASE_H | ||
| 2 | #define EXCEPTION_BASE_H | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | #include <exception> | ||
| 6 | #include <stdarg.h> | ||
| 7 | |||
| 8 | /** | ||
| 9 | * A generalized Exception base class. This is nice for making general and | ||
| 10 | * flexible child classes that can create new error code classes. | ||
| 11 | */ | ||
| 12 | class ExceptionBase : public std::exception | ||
| 13 | { | ||
| 14 | public: | ||
| 15 | /** | ||
| 16 | * Construct an exception with an error code of zero, but with a | ||
| 17 | * description. The use of this is not reccomended most of the time, it's | ||
| 18 | * generally best to include an error code with the exception so your | ||
| 19 | * program can handle the exception in a better way. | ||
| 20 | * @param sFormat The format of the text. See printf for more info. | ||
| 21 | */ | ||
| 22 | ExceptionBase( const char *sFormat, ... ) throw(); | ||
| 23 | |||
| 24 | /** | ||
| 25 | * | ||
| 26 | * @param nCode | ||
| 27 | * @param sFormat | ||
| 28 | */ | ||
| 29 | ExceptionBase( int nCode, const char *sFormat, ... ) throw(); | ||
| 30 | |||
| 31 | /** | ||
| 32 | * | ||
| 33 | * @param nCode | ||
| 34 | * @return | ||
| 35 | */ | ||
| 36 | ExceptionBase( int nCode=0 ) throw(); | ||
| 37 | |||
| 38 | /** | ||
| 39 | * | ||
| 40 | * @return | ||
| 41 | */ | ||
| 42 | virtual ~ExceptionBase() throw(); | ||
| 43 | |||
| 44 | /** | ||
| 45 | * | ||
| 46 | * @return | ||
| 47 | */ | ||
| 48 | virtual const char *what() const throw(); | ||
| 49 | |||
| 50 | /** | ||
| 51 | * | ||
| 52 | * @return | ||
| 53 | */ | ||
| 54 | int getErrorCode(); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * | ||
| 58 | * @param lpFormat | ||
| 59 | * @param vargs | ||
| 60 | */ | ||
| 61 | void setWhat( const char *lpFormat, va_list &vargs ); | ||
| 62 | |||
| 63 | private: | ||
| 64 | char *sWhat; /**< The text string telling people what went wrong. */ | ||
| 65 | int nErrorCode; /**< The code for the error that occured. */ | ||
| 66 | }; | ||
| 67 | |||
| 68 | #define subExceptionDecl( name ) \ | ||
| 69 | class name : public ExceptionBase \ | ||
| 70 | { \ | ||
| 71 | public: \ | ||
| 72 | name( const char *sFormat, ... ) throw (); \ | ||
| 73 | name( int nCode, const char *sFormat, ... ) throw(); \ | ||
| 74 | name( int nCode=0 ) throw (); \ | ||
| 75 | }; | ||
| 76 | |||
| 77 | #define subExceptionDef( name ) \ | ||
| 78 | name::name( const char *lpFormat, ... ) throw() : \ | ||
| 79 | ExceptionBase( 0 ) \ | ||
| 80 | { \ | ||
| 81 | va_list ap; \ | ||
| 82 | va_start( ap, lpFormat ); \ | ||
| 83 | setWhat( lpFormat, ap ); \ | ||
| 84 | va_end( ap ); \ | ||
| 85 | } \ | ||
| 86 | name::name( int nCode, const char *lpFormat, ... ) throw() : \ | ||
| 87 | ExceptionBase( nCode ) \ | ||
| 88 | { \ | ||
| 89 | va_list ap; \ | ||
| 90 | va_start( ap, lpFormat ); \ | ||
| 91 | setWhat( lpFormat, ap ); \ | ||
| 92 | va_end( ap ); \ | ||
| 93 | } \ | ||
| 94 | name::name( int nCode ) throw() : \ | ||
| 95 | ExceptionBase( nCode ) \ | ||
| 96 | { \ | ||
| 97 | } | ||
| 98 | |||
| 99 | #endif | ||
