diff --git a/Utils/Exception.cc b/Utils/Exception.cc index a5349100137cb5434ff65ec61c6565953b3bbd3c..c9a43f111f6ca8748406f9b7dfdc66af580286a9 100644 --- a/Utils/Exception.cc +++ b/Utils/Exception.cc @@ -27,14 +27,24 @@ // Custom includes #include <cstring> +#include <sstream> #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// +prefix_ void satcom::lib::SystemException::init() +{ + std::stringstream s; + if (where) + s << where << ": "; + s << "(" << err << ") " << std::strerror(err); + buffer_ = s.str(); +} + prefix_ char const * satcom::lib::SystemException::what() const throw() { - return std::strerror(this->err); + return buffer_.c_str(); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Utils/Exception.hh b/Utils/Exception.hh index 6c3e8b13ec260fdf53736d7f3b9ab242587e0724..1c5ca1ca7dede6088e95f1d870acb4d515ff5d05 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -25,6 +25,7 @@ // Custom includes #include <exception> +#include <string> //#include "Exception.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -34,9 +35,18 @@ namespace lib { struct SystemException : public std::exception { - SystemException(int err_) : err(err_) {}; + explicit SystemException(int err_) : where(0), err(err_) { init(); } + SystemException(char const * where_, int err_) : where(where_), err(err_) { init(); } + virtual char const * what() const throw(); + + char const * where; int err; + + virtual ~SystemException() throw() {} + private: + void init(); + std::string buffer_; }; }}