X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.cc;h=b2c750f383c55a27d449c0853fdec59a085b4fa2;hb=412024ed31a4ab4eaea7a4165a434f8efebee325;hp=5e692773f0a7725353e5c8837a8c032527148630;hpb=1d247d12d1759ffd77f456efe3a52f03dd289994;p=senf.git diff --git a/Utils/Exception.cc b/Utils/Exception.cc index 5e69277..b2c750f 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -27,6 +27,10 @@ //#include "Exception.ih" // Custom includes +#include +#include +#include "../config.hh" +#include "Backtrace.hh" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// @@ -34,6 +38,23 @@ /////////////////////////////////////////////////////////////////////////// // senf::Exception +#ifdef SENF_DEBUG +prefix_ void senf::ExceptionMixin::addBacktrace() +{ + void * entries[SENF_DEBUG_BACKTRACE_NUMCALLERS]; + unsigned nEntries( ::backtrace(entries, SENF_DEBUG_BACKTRACE_NUMCALLERS) ); + + std::stringstream ss; + ss << "\nException at\n"; + formatBacktrace(ss, entries, nEntries); + ss << "-- \n" << message_; + message_ = ss.str(); +} +#endif + +/////////////////////////////////////////////////////////////////////////// +// senf::Exception + prefix_ senf::Exception::~Exception() throw() {} @@ -41,7 +62,22 @@ prefix_ senf::Exception::~Exception() prefix_ char const * senf::Exception::what() const throw() { - return message_.c_str(); + return message().c_str(); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::SystemException + +prefix_ void senf::SystemException::init(std::string const & descr, int code + _SENF_EXC_DEBUG_ARGS_ND) +{ + code_ = code; +# ifdef SENF_DEBUG + if (file && line) + (*this) << "Exception at " << file << ":" << line << "\n"; +# endif + (*this) << "[" << errorString() << "]"; + if (! descr.empty()) (*this) << " " << descr; } ///////////////////////////////cc.e////////////////////////////////////////