From 9056ed898953108d7dfc3b3e35ee7a0d259e3659 Mon Sep 17 00:00:00 2001 From: nojhan Date: Thu, 6 Feb 2020 21:55:12 +0100 Subject: [PATCH] add an eoSystemError exception - make members const in eoException.h classes --- eo/src/eoExceptions.h | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/eo/src/eoExceptions.h b/eo/src/eoExceptions.h index 56b5fbfd8..ef1a5c67e 100644 --- a/eo/src/eoExceptions.h +++ b/eo/src/eoExceptions.h @@ -52,7 +52,7 @@ public: } private: - time_t _elapsed; + const time_t _elapsed; }; @@ -76,7 +76,7 @@ public: } private: - unsigned long _threshold; + const unsigned long _threshold; }; @@ -102,7 +102,7 @@ public: ~eoMissingParamException() throw() {} private: - std::string _name; + const std::string _name; }; /*! @@ -127,7 +127,40 @@ public: ~eoWrongParamTypeException() throw() {} private: - std::string _name; + const std::string _name; +}; + + +class eoSystemError : public std::exception +{ +public: + eoSystemError(std::string cmd) + : _cmd(cmd), _has_pipe(false), _err_code(-1), _output("") + {} + + eoSystemError(std::string cmd, int err_code, std::string output) + : _cmd(cmd), _has_pipe(true), _err_code(err_code), _output(output) + {} + + virtual const char* what() const throw() + { + std::ostringstream ss; + ss << "System call: `" << _cmd << "` error"; + if(_has_pipe) { + ss << " code #" << _err_code + << " with the following output:" << std::endl << _output; + } + return ss.str().c_str(); + } + + ~eoSystemError() throw() {} + +private: + const std::string _cmd; + const bool _has_pipe; + const int _err_code; + const std::string _output; + }; #endif // __eoExceptions_h__