X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.cc;h=737214da96347dc62763ff4750117b18d406902a;hb=a1fdb7bb122f0b05be809a922d4b7ef5e125fa67;hp=61d5860d8b624c3a4666c17738d9b86fcf6f9894;hpb=a66bffcc77f006b22190e1c27cbe0cd75fc4501c;p=senf.git diff --git a/Utils/Exception.cc b/Utils/Exception.cc index 61d5860..737214d 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_; + what_ = ss.str(); +} +#endif + +/////////////////////////////////////////////////////////////////////////// +// senf::Exception + prefix_ senf::Exception::~Exception() throw() {} @@ -41,17 +62,22 @@ prefix_ senf::Exception::~Exception() prefix_ char const * senf::Exception::what() const throw() { - return message_.c_str(); + return what_.c_str(); } /////////////////////////////////////////////////////////////////////////// // senf::SystemException -prefix_ void senf::SystemException::init(std::string const & descr, int code) +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; + if (! descr.empty()) (*this) << " " << descr; } ///////////////////////////////cc.e////////////////////////////////////////