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: IpmiException(int ipmicc)32 explicit IpmiException(int ipmicc) : 33 _message("IPMI Code Received: " + std::to_string(ipmicc)), 34 _ipmicc(ipmicc) 35 {} 36 what() const37 virtual const char* what() const noexcept override 38 { 39 return _message.c_str(); 40 } 41 getIpmiError() const42 int getIpmiError() const 43 { 44 return _ipmicc; 45 } 46 47 private: 48 std::string _message; 49 int _ipmicc; 50 }; 51 52 } // namespace ipmi 53 } // namespace google 54