From bc6f456ef27bdf25bf7a7f677217b9b7204b4241 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 13 May 2006 02:24:07 +0000 Subject: Added a nice, generic exception class. It really helps out a lot. I dunno if it's better to create a new subclass of it for each situation, but it is cool... --- src/exception.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/exception.cpp (limited to 'src/exception.cpp') diff --git a/src/exception.cpp b/src/exception.cpp new file mode 100644 index 0000000..11f04a9 --- /dev/null +++ b/src/exception.cpp @@ -0,0 +1,44 @@ +#include "exception.h" +#include + +Exception::Exception( const char *lpFormat, ... ) throw() : + nErrorCode( 0 ) +{ + va_list ap; + int nSize; + + va_start(ap, lpFormat); + nSize = vsnprintf( NULL, 0, lpFormat, ap ); + sWhat = new char[nSize+1]; + vsnprintf( sWhat, nSize+1, lpFormat, ap ); + va_end(ap); +} + +Exception::Exception( int nCode, const char *lpFormat, ... ) throw() : + nErrorCode( nCode ) +{ + va_list ap; + int nSize; + + va_start(ap, lpFormat); + nSize = vsnprintf( NULL, 0, lpFormat, ap ); + sWhat = new char[nSize+1]; + vsnprintf( sWhat, nSize+1, lpFormat, ap ); + va_end(ap); +} + +Exception::~Exception() throw() +{ + delete[] sWhat; +} + +const char *Exception::what() const throw() +{ + return sWhat; +} + +int Exception::getErrorCode() +{ + return nErrorCode; +} + -- cgit v1.2.3