From 9e27762c2b4c1baf5b2aff003fbc56236fd742e6 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 26 Jul 2006 19:09:50 +0000 Subject: Partial update, don't use this release... --- src/exception.cpp | 60 --------------------------------------------------- src/exception.h | 31 ++++++++++++++++++++++++++ src/exceptionbase.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/xmlexception.cpp | 4 ++++ src/xmlexception.h | 21 ++++-------------- 5 files changed, 99 insertions(+), 77 deletions(-) delete mode 100644 src/exception.cpp create mode 100644 src/exceptionbase.cpp (limited to 'src') diff --git a/src/exception.cpp b/src/exception.cpp deleted file mode 100644 index 3cde134..0000000 --- a/src/exception.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "exception.h" -#include - -Exception::Exception( const char *lpFormat, ... ) throw() : - nErrorCode( 0 ), - sWhat( NULL ) -{ - va_list ap; - - va_start(ap, lpFormat); - setWhat( lpFormat, ap ); - va_end(ap); -} - -Exception::Exception( int nCode, const char *lpFormat, ... ) throw() : - nErrorCode( nCode ), - sWhat( NULL ) -{ - va_list ap; - - va_start(ap, lpFormat); - setWhat( lpFormat, ap ); - va_end(ap); -} - -Exception::Exception( int nCode ) throw() : - nErrorCode( nCode ), - sWhat( NULL ) -{ -} - -Exception::~Exception() throw() -{ - if( sWhat ) - { - delete[] sWhat; - sWhat = NULL; - } -} - -void Exception::setWhat( const char *lpFormat, va_list &vargs ) -{ - if( sWhat ) delete[] sWhat; - int nSize; - - nSize = vsnprintf( NULL, 0, lpFormat, vargs ); - sWhat = new char[nSize+1]; - vsnprintf( sWhat, nSize+1, lpFormat, vargs ); -} - -const char *Exception::what() const throw() -{ - return sWhat; -} - -int Exception::getErrorCode() -{ - return nErrorCode; -} - diff --git a/src/exception.h b/src/exception.h index 2233736..1234bef 100644 --- a/src/exception.h +++ b/src/exception.h @@ -65,4 +65,35 @@ private: int nErrorCode; /**< The code for the error that occured. */ }; +#define subExceptionDecl( name ) \ +class name : public Exception \ +{ \ + public: \ + name( const char *sFormat, ... ) throw (); \ + name( int nCode, const char *sFormat, ... ) throw(); \ + name( int nCode=0 ) throw (); \ +}; + +#define subExceptionDef( name ) \ +name::name( const char *lpFormat, ... ) throw() : \ + Exception( 0 ) \ +{ \ + va_list ap; \ + va_start( ap, lpFormat ); \ + setWhat( lpFormat, ap ); \ + va_end( ap ); \ +} \ +name::name( int nCode, const char *lpFormat, ... ) throw() : \ + Exception( nCode ) \ +{ \ + va_list ap; \ + va_start( ap, lpFormat ); \ + setWhat( lpFormat, ap ); \ + va_end( ap ); \ +} \ +name::name( int nCode ) throw() : \ + Exception( nCode ) \ +{ \ +} + #endif diff --git a/src/exceptionbase.cpp b/src/exceptionbase.cpp new file mode 100644 index 0000000..3cde134 --- /dev/null +++ b/src/exceptionbase.cpp @@ -0,0 +1,60 @@ +#include "exception.h" +#include + +Exception::Exception( const char *lpFormat, ... ) throw() : + nErrorCode( 0 ), + sWhat( NULL ) +{ + va_list ap; + + va_start(ap, lpFormat); + setWhat( lpFormat, ap ); + va_end(ap); +} + +Exception::Exception( int nCode, const char *lpFormat, ... ) throw() : + nErrorCode( nCode ), + sWhat( NULL ) +{ + va_list ap; + + va_start(ap, lpFormat); + setWhat( lpFormat, ap ); + va_end(ap); +} + +Exception::Exception( int nCode ) throw() : + nErrorCode( nCode ), + sWhat( NULL ) +{ +} + +Exception::~Exception() throw() +{ + if( sWhat ) + { + delete[] sWhat; + sWhat = NULL; + } +} + +void Exception::setWhat( const char *lpFormat, va_list &vargs ) +{ + if( sWhat ) delete[] sWhat; + int nSize; + + nSize = vsnprintf( NULL, 0, lpFormat, vargs ); + sWhat = new char[nSize+1]; + vsnprintf( sWhat, nSize+1, lpFormat, vargs ); +} + +const char *Exception::what() const throw() +{ + return sWhat; +} + +int Exception::getErrorCode() +{ + return nErrorCode; +} + diff --git a/src/xmlexception.cpp b/src/xmlexception.cpp index 7012ee6..9f38844 100644 --- a/src/xmlexception.cpp +++ b/src/xmlexception.cpp @@ -1,6 +1,9 @@ #include "xmlexception.h" #include +subExceptionDef( XmlException ) + +/* XmlException::XmlException( const char *lpFormat, ... ) throw() : Exception( 0 ) { @@ -25,3 +28,4 @@ XmlException::XmlException( int nCode ) throw() : Exception( nCode ) { } +*/ diff --git a/src/xmlexception.h b/src/xmlexception.h index 9437ba3..5cbeda7 100644 --- a/src/xmlexception.h +++ b/src/xmlexception.h @@ -5,30 +5,17 @@ #include "exception.h" #include -/** - * A generalized Exception base class. This is nice for making general and - * flexible child classes that can create new error code classes. - */ +subExceptionDecl( XmlException ) + +/* class XmlException : public Exception { public: - /** - * Construct an exception with an error code of zero, but with a - * description. The use of this is not reccomended most of the time, it's - * generally best to include an error code with the exception so your - * program can handle the exception in a better way. - * @param sFormat The format of the text. See printf for more info. - */ XmlException( const char *sFormat, ... ) throw(); - /** - * - * @param nCode - * @param sFormat - */ XmlException( int nCode, const char *sFormat, ... ) throw(); XmlException( int nCode=0 ) throw(); -}; +};*/ #endif -- cgit v1.2.3