From: Christian P. <cp...@us...> - 2005-07-01 13:53:02
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16708/src Modified Files: Exception.cpp Log Message: - Removed std::string from Exception. The base exception should not throw in any case - Fixed CmdLineError and added extra exception info field Index: Exception.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Exception.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Exception.cpp 25 Dec 2004 00:04:38 -0000 1.6 +++ Exception.cpp 1 Jul 2005 13:52:51 -0000 1.7 @@ -19,21 +19,17 @@ ***************************************************************************/ #include "pclasses/Exception.h" +#include <sstream> namespace P { Exception::Exception(const char* what, const SourceInfo& si) throw() - : _what(what?what:""), _source(&si), _where("") -{ -} - -Exception::Exception(const std::string & what, const SourceInfo& si) throw() - : _what(what), _source(&si), _where("") + : _what(what ? what : ""), _source(&si) { } Exception::Exception(const Exception& err) throw() - : _what(err._what), _source(err._source), _where(err._where) + : _what(err._what), _source(err._source) { } @@ -41,41 +37,46 @@ { } -const char * Exception::where() const throw() +std::string Exception::where() const { - if( _where.empty() && _source ) + std::ostringstream where; + + where << "["; + if(_source->file()) { - _where = "["; - if( _source->file() ) - { - _where += "file = "; - _where += _source->file(); - } - if( _source->line() ) - { - _where += ": line = "; - _where += _source->line(); - } -// if( _source->func() ) -// { -// _where += " : function = "; -// _where += _source->func(); // segfault here -// } - _where += "]"; + where << "file = "; + where << _source->file(); } - return _where.c_str(); + + where << ": line = "; + where << _source->line(); + + if(_source->func()) + { + where << " : function = "; + where << _source->func(); + } + + where << "]"; + return where.str(); } const char* Exception::what() const throw() { - return _what.c_str(); + return _what; } Exception& Exception::operator=(const Exception& err) throw() { _what = err._what; _source = err._source; - return *this; + return *this; +} + +std::ostream& operator<<(std::ostream& os, const Exception& err) +{ + os << "Exception: " << err.what() << ' ' << err.where(); + return os; } @@ -94,11 +95,6 @@ { } -RuntimeError::RuntimeError(const std::string & what, const SourceInfo& si) throw() -: Exception(what, si) -{ -} - RuntimeError::~RuntimeError() throw() { } @@ -108,10 +104,6 @@ : RuntimeError(what, si) { } -OutOfBounds::OutOfBounds(const std::string & what, const SourceInfo& si) throw() -: RuntimeError(what, si) -{ -} OutOfBounds::~OutOfBounds() throw() { @@ -122,10 +114,6 @@ : RuntimeError(what, si) { } -OverrunError::OverrunError(const std::string & what, const SourceInfo& si) throw() -: RuntimeError(what, si) -{ -} OverrunError::~OverrunError() throw() { @@ -136,10 +124,6 @@ : RuntimeError(what, si) { } -UnderrunError::UnderrunError(const std::string & what, const SourceInfo& si) throw() -: RuntimeError(what, si) -{ -} UnderrunError::~UnderrunError() throw() { @@ -150,12 +134,18 @@ : RuntimeError(what, si) { } -OverflowError::OverflowError(const std::string & what, const SourceInfo& si) throw() + +OverflowError::~OverflowError() throw() +{ +} + + +ConversionError::ConversionError(const char* what, const SourceInfo& si) throw() : RuntimeError(what, si) { } -OverflowError::~OverflowError() throw() +ConversionError::~ConversionError() throw() { } |