diff options
author | Patrick Venture <venture@google.com> | 2019-05-29 09:33:49 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-05-29 09:52:38 -0700 |
commit | ef5e09252dba451acda30e53e8f5b28f08eac0cb (patch) | |
tree | 0ada146ec683a3bde9ff597f31d161042daa8b05 | |
parent | 444746495ad3f951cb093c7144b7cb9218b8599f (diff) | |
download | ipmi-blob-tool-ef5e09252dba451acda30e53e8f5b28f08eac0cb.tar.gz ipmi-blob-tool-ef5e09252dba451acda30e53e8f5b28f08eac0cb.zip |
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 <venture@google.com>
-rw-r--r-- | src/ipmiblob/ipmi_errors.hpp | 18 |
1 files 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 |