From 469bbcf0701e1eb8a6670c23145b0da87357e178 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 25 Mar 2012 20:00:08 +0000 Subject: Code is all reorganized. We're about ready to release. I should write up a little explenation of the arrangement. --- src/stable/exceptionbase.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/stable/exceptionbase.cpp (limited to 'src/stable/exceptionbase.cpp') diff --git a/src/stable/exceptionbase.cpp b/src/stable/exceptionbase.cpp new file mode 100644 index 0000000..13a98db --- /dev/null +++ b/src/stable/exceptionbase.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2007-2011 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/exceptionbase.h" +#include +#include +#include + +Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() : + nErrorCode( 0 ), + sWhat( NULL ) +{ + va_list ap; + + va_start(ap, lpFormat); + setWhat( lpFormat, ap ); + va_end(ap); +} + +Bu::ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() : + nErrorCode( nCode ), + sWhat( NULL ) +{ + va_list ap; + + va_start(ap, lpFormat); + setWhat( lpFormat, ap ); + va_end(ap); +} + +Bu::ExceptionBase::ExceptionBase( int nCode ) throw() : + nErrorCode( nCode ), + sWhat( NULL ) +{ +} + +Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () : + std::exception( e ), + nErrorCode( e.nErrorCode ), + sWhat( NULL ) +{ + setWhat( e.sWhat ); +} + +Bu::ExceptionBase::~ExceptionBase() throw() +{ + delete[] sWhat; + sWhat = NULL; +} + +void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs ) +{ + if( sWhat ) delete[] sWhat; + int nSize; + + va_list vargs2; + va_copy( vargs2, vargs ); + nSize = vsnprintf( NULL, 0, lpFormat, vargs2 ); + va_end( vargs2 ); + sWhat = new char[nSize+1]; + vsnprintf( sWhat, nSize+1, lpFormat, vargs ); +} + +void Bu::ExceptionBase::setWhat( const char *lpText ) +{ + if( sWhat ) delete[] sWhat; + int nSize; + + nSize = strlen( lpText ); + sWhat = new char[nSize+1]; + strcpy( sWhat, lpText ); +} + +const char *Bu::ExceptionBase::what() const throw() +{ + return sWhat; +} + +int Bu::ExceptionBase::getErrorCode() +{ + return nErrorCode; +} + +Bu::UnsupportedException::UnsupportedException() throw() : + ExceptionBase( 0 ) +{ + setWhat("An unsupperted operation was attempted."); +} + -- cgit v1.2.3