From: stephan b. <st...@s1...> - 2004-12-20 22:18:07
|
Yo, again! Having to pass a SourceInfo is pretty laestig in client code... but it IS a really clever idea, once you realize the P_SOURCEINFO macro is there to help it's not bad. However, i figure that since we HAVE the SourceInfo, why not USE it? Here's a proposed change to BaseError. None of the interface changes. The ctor prefixes the SourceInfo to the 'what' string. The result calling what() now includes the file, line and function name: BaseError: piomanager.cpp:99:P::IOHandler* P::IOManager::findCreateHandler(const std::string&): No handler for protocol found. One could argue that we shouldn't do memory allocation like this from BaseError, but allocation errors, and errors of that severity, happen via the std::exceptions, not via BaseError. Also, on Linux malloc() "never fails", so it's theoretically impossible to know if there is more memory without counting it yourself (see man malloc on a Linux box, in the BUGS section). Here's the proposed code, from pexception.h: #include <sstream> inline BaseError(const char* _what, const SourceInfo& _si) throw() : m_what(_what), m_sourceInfo(_si) { std::ostringstream os; os << _si.file() << ":"<<_si.line()<<":" << _si.func()<<": " << _what; m_what = os.str(); } inline const char* what() const throw() { return m_what.c_str(); } std::string m_what; -- ----- st...@s1... http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts |