X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.cci;h=40d89a5f6106aff1326a4ac74c0a5c4800f1c5df;hb=28275a1a9075ae42dc29aaadc5bc78e6fa204e26;hp=565ed2e12fd498e5483365a5ba4582c05b6095dc;hpb=553781d9e9bce316dca24ac4f0c42e5613e849e0;p=senf.git diff --git a/Utils/Exception.cci b/Utils/Exception.cci index 565ed2e..40d89a5 100644 --- a/Utils/Exception.cci +++ b/Utils/Exception.cci @@ -21,30 +21,90 @@ \brief Exception inline non-template implementation */ // Custom includes +#include +#include #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// -prefix_ senf::SystemException::SystemException(int err_) - : where(0), err(err_) +prefix_ senf::SystemException::SystemException(SystemException const & other) + : std::stringstream(other.str(),std::ios::out), code_(other.code_) +{} + +prefix_ senf::SystemException::SystemException(std::string const & where, int code) + : std::stringstream(std::ios::out), code_(code) +{ + if (! where.empty()) + (*this) << where << ": "; + (*this) << "(" << code_ << ") " << description(); +} + +prefix_ char const * senf::SystemException::what() + const throw() { - init(); + /// \fixme Replace the 'stringstream' base-class with our own stream with a specialized + /// streambuf which allows to efficiently access the contents as a C string. + buffer_ = this->str(); + return buffer_.c_str(); } -prefix_ senf::SystemException::SystemException(char const * where_, int err_) - : where(where_), err(err_) -{ - init(); +prefix_ int senf::SystemException::errorNumber() + const +{ + return code_; +} + +prefix_ char const * senf::SystemException::description() + const +{ + return std::strerror(code_); +} + +prefix_ bool senf::SystemException::anyOf(int c0, int c1, int c2, int c3, int c4, int c5, + int c6, int c7, int c8, int c9) +{ + return + (c0 && code_ == c0) || + (c1 && code_ == c1) || + (c2 && code_ == c2) || + (c3 && code_ == c3) || + (c4 && code_ == c4) || + (c5 && code_ == c5) || + (c6 && code_ == c6) || + (c7 && code_ == c7) || + (c8 && code_ == c8) || + (c9 && code_ == c9); } prefix_ senf::SystemException::~SystemException() throw() {} +prefix_ void senf::throwErrno() +{ + throwErrno("", errno); +} + +prefix_ void senf::throwErrno(std::string const & where) +{ + throwErrno(where, errno); +} + +prefix_ void senf::throwErrno(int code) +{ + throwErrno("", code); +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: