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>
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 @@
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 @@
}
}
- 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 @@
return _message.c_str();
}
+ int code() const noexcept
+ {
+ return _ccode;
+ }
+
private:
std::string _message;
+ int _ccode = 0;
};
} // namespace ipmiblob