xref: /openbmc/google-ipmi-sys/errors.hpp (revision 6c71b0f9)
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <exception>
18 #include <string>
19 
20 namespace google
21 {
22 namespace ipmi
23 {
24 
25 /**
26  * This can be used by the Handler object to throw an exception and suggest an
27  * IPMI return code to use for the error.
28  */
29 class IpmiException : public std::exception
30 {
31   public:
32     explicit IpmiException(int ipmicc) :
33         _message("IPMI Code Received: " + std::to_string(ipmicc)),
34         _ipmicc(ipmicc)
35     {
36     }
37 
38     virtual const char* what() const noexcept override
39     {
40         return _message.c_str();
41     }
42 
43     int getIpmiError() const
44     {
45         return _ipmicc;
46     }
47 
48   private:
49     std::string _message;
50     int _ipmicc;
51 };
52 
53 } // namespace ipmi
54 } // namespace google
55