From 579c3ac445043122b0a702bdb2542d9ea404b62e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 26 Jul 2006 19:16:58 +0000 Subject: Exceptions have been re-worked, and are easier to use, and don't collide with system includues anymore. --- src/exception.h | 99 ------------------------------------------------- src/exceptionbase.cpp | 16 ++++---- src/exceptionbase.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ src/exceptions.cpp | 5 +++ src/exceptions.h | 9 +++++ src/xmlexception.cpp | 31 ---------------- src/xmlexception.h | 21 ----------- src/xmlfilereader.cpp | 2 +- src/xmlreader.cpp | 2 +- src/xmlstringreader.cpp | 2 +- 10 files changed, 124 insertions(+), 162 deletions(-) delete mode 100644 src/exception.h create mode 100644 src/exceptionbase.h create mode 100644 src/exceptions.cpp create mode 100644 src/exceptions.h delete mode 100644 src/xmlexception.cpp delete mode 100644 src/xmlexception.h diff --git a/src/exception.h b/src/exception.h deleted file mode 100644 index 1234bef..0000000 --- a/src/exception.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef EXCEPTION_H -#define EXCEPTION_H - -#include -#include -#include - -/** - * A generalized Exception base class. This is nice for making general and - * flexible child classes that can create new error code classes. - */ -class Exception : public std::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. - */ - Exception( const char *sFormat, ... ) throw(); - - /** - * - * @param nCode - * @param sFormat - */ - Exception( int nCode, const char *sFormat, ... ) throw(); - - /** - * - * @param nCode - * @return - */ - Exception( int nCode=0 ) throw(); - - /** - * - * @return - */ - virtual ~Exception() throw(); - - /** - * - * @return - */ - virtual const char *what() const throw(); - - /** - * - * @return - */ - int getErrorCode(); - - /** - * - * @param lpFormat - * @param vargs - */ - void setWhat( const char *lpFormat, va_list &vargs ); - -private: - char *sWhat; /**< The text string telling people what went wrong. */ - 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 index 3cde134..a9b9820 100644 --- a/src/exceptionbase.cpp +++ b/src/exceptionbase.cpp @@ -1,7 +1,7 @@ -#include "exception.h" +#include "exceptionbase.h" #include -Exception::Exception( const char *lpFormat, ... ) throw() : +ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() : nErrorCode( 0 ), sWhat( NULL ) { @@ -12,7 +12,7 @@ Exception::Exception( const char *lpFormat, ... ) throw() : va_end(ap); } -Exception::Exception( int nCode, const char *lpFormat, ... ) throw() : +ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() : nErrorCode( nCode ), sWhat( NULL ) { @@ -23,13 +23,13 @@ Exception::Exception( int nCode, const char *lpFormat, ... ) throw() : va_end(ap); } -Exception::Exception( int nCode ) throw() : +ExceptionBase::ExceptionBase( int nCode ) throw() : nErrorCode( nCode ), sWhat( NULL ) { } -Exception::~Exception() throw() +ExceptionBase::~ExceptionBase() throw() { if( sWhat ) { @@ -38,7 +38,7 @@ Exception::~Exception() throw() } } -void Exception::setWhat( const char *lpFormat, va_list &vargs ) +void ExceptionBase::setWhat( const char *lpFormat, va_list &vargs ) { if( sWhat ) delete[] sWhat; int nSize; @@ -48,12 +48,12 @@ void Exception::setWhat( const char *lpFormat, va_list &vargs ) vsnprintf( sWhat, nSize+1, lpFormat, vargs ); } -const char *Exception::what() const throw() +const char *ExceptionBase::what() const throw() { return sWhat; } -int Exception::getErrorCode() +int ExceptionBase::getErrorCode() { return nErrorCode; } 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 @@ +#ifndef EXCEPTION_BASE_H +#define EXCEPTION_BASE_H + +#include +#include +#include + +/** + * A generalized Exception base class. This is nice for making general and + * flexible child classes that can create new error code classes. + */ +class ExceptionBase : public std::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. + */ + ExceptionBase( const char *sFormat, ... ) throw(); + + /** + * + * @param nCode + * @param sFormat + */ + ExceptionBase( int nCode, const char *sFormat, ... ) throw(); + + /** + * + * @param nCode + * @return + */ + ExceptionBase( int nCode=0 ) throw(); + + /** + * + * @return + */ + virtual ~ExceptionBase() throw(); + + /** + * + * @return + */ + virtual const char *what() const throw(); + + /** + * + * @return + */ + int getErrorCode(); + + /** + * + * @param lpFormat + * @param vargs + */ + void setWhat( const char *lpFormat, va_list &vargs ); + +private: + char *sWhat; /**< The text string telling people what went wrong. */ + int nErrorCode; /**< The code for the error that occured. */ +}; + +#define subExceptionDecl( name ) \ +class name : public ExceptionBase \ +{ \ + 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() : \ + ExceptionBase( 0 ) \ +{ \ + va_list ap; \ + va_start( ap, lpFormat ); \ + setWhat( lpFormat, ap ); \ + va_end( ap ); \ +} \ +name::name( int nCode, const char *lpFormat, ... ) throw() : \ + ExceptionBase( nCode ) \ +{ \ + va_list ap; \ + va_start( ap, lpFormat ); \ + setWhat( lpFormat, ap ); \ + va_end( ap ); \ +} \ +name::name( int nCode ) throw() : \ + ExceptionBase( nCode ) \ +{ \ +} + +#endif diff --git a/src/exceptions.cpp b/src/exceptions.cpp new file mode 100644 index 0000000..441075d --- /dev/null +++ b/src/exceptions.cpp @@ -0,0 +1,5 @@ +#include "exceptions.h" +#include + +subExceptionDef( XmlException ) + diff --git a/src/exceptions.h b/src/exceptions.h new file mode 100644 index 0000000..1cc891d --- /dev/null +++ b/src/exceptions.h @@ -0,0 +1,9 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +#include "exceptionbase.h" +#include + +subExceptionDecl( XmlException ) + +#endif diff --git a/src/xmlexception.cpp b/src/xmlexception.cpp deleted file mode 100644 index 9f38844..0000000 --- a/src/xmlexception.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "xmlexception.h" -#include - -subExceptionDef( XmlException ) - -/* -XmlException::XmlException( const char *lpFormat, ... ) throw() : - Exception( 0 ) -{ - va_list ap; - - va_start(ap, lpFormat); - setWhat( lpFormat, ap ); - va_end(ap); -} - -XmlException::XmlException( int nCode, const char *lpFormat, ... ) throw() : - Exception( nCode ) -{ - va_list ap; - - va_start(ap, lpFormat); - setWhat( lpFormat, ap ); - va_end(ap); -} - -XmlException::XmlException( int nCode ) throw() : - Exception( nCode ) -{ -} -*/ diff --git a/src/xmlexception.h b/src/xmlexception.h deleted file mode 100644 index 5cbeda7..0000000 --- a/src/xmlexception.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef XML_EXCEPTION_H -#define XML_EXCEPTION_H - -#include -#include "exception.h" -#include - -subExceptionDecl( XmlException ) - -/* -class XmlException : public Exception -{ -public: - XmlException( const char *sFormat, ... ) throw(); - - XmlException( int nCode, const char *sFormat, ... ) throw(); - - XmlException( int nCode=0 ) throw(); -};*/ - -#endif diff --git a/src/xmlfilereader.cpp b/src/xmlfilereader.cpp index eb0ff9c..ed674a8 100644 --- a/src/xmlfilereader.cpp +++ b/src/xmlfilereader.cpp @@ -1,5 +1,5 @@ #include "xmlfilereader.h" -#include "xmlexception.h" +#include "exceptions.h" #include XmlFileReader::XmlFileReader( const char *sFile, bool bStrip ) diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp index 2a5f63f..d51568c 100644 --- a/src/xmlreader.cpp +++ b/src/xmlreader.cpp @@ -1,5 +1,5 @@ #include "xmlreader.h" -#include "xmlexception.h" +#include "exceptions.h" #include #include "hashfunctionstring.h" diff --git a/src/xmlstringreader.cpp b/src/xmlstringreader.cpp index 211df78..3956ff3 100644 --- a/src/xmlstringreader.cpp +++ b/src/xmlstringreader.cpp @@ -1,5 +1,5 @@ #include "xmlstringreader.h" -#include "xmlexception.h" +#include "exceptions.h" #include XmlStringReader::XmlStringReader( const char *sString, bool bStrip ) -- cgit v1.2.3