From ef5e09252dba451acda30e53e8f5b28f08eac0cb Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Wed, 29 May 2019 09:33:49 -0700 Subject: ipmi exceptions: add method to grab code Add a method to grab the underlying code to allow easier repackaging of the exception into something else. Change-Id: Icf25254c612926429f623d757998c3927966e0aa Signed-off-by: Patrick Venture --- src/ipmiblob/ipmi_errors.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ipmiblob/ipmi_errors.hpp b/src/ipmiblob/ipmi_errors.hpp index e41b3cf..15a5d4c 100644 --- a/src/ipmiblob/ipmi_errors.hpp +++ b/src/ipmiblob/ipmi_errors.hpp @@ -10,7 +10,8 @@ namespace ipmiblob class IpmiException : public std::exception { public: - explicit IpmiException(const std::string& message) : _message(message){}; + IpmiException(const std::string& message, int code) : + _message(message), _ccode(code){}; static std::string messageFromIpmi(int cc) { @@ -31,7 +32,14 @@ class IpmiException : public std::exception } } - explicit IpmiException(int cc) : IpmiException(messageFromIpmi(cc)) + /* This will leave the code as 0, but by virtue of being an exception + * thrown, we'll know it was an error on the host-side. + */ + explicit IpmiException(const std::string& message) : _message(message) + { + } + + explicit IpmiException(int cc) : IpmiException(messageFromIpmi(cc), cc) { } @@ -40,8 +48,14 @@ class IpmiException : public std::exception return _message.c_str(); } + int code() const noexcept + { + return _ccode; + } + private: std::string _message; + int _ccode = 0; }; } // namespace ipmiblob -- cgit v1.2.3