Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 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 | |
Patrick Venture | d2037c6 | 2019-03-15 10:29:47 -0700 | [diff] [blame] | 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) |
Patrick Williams | 444b5ea | 2023-05-19 13:56:42 -0500 | [diff] [blame] | 35 | {} |
Patrick Venture | d2037c6 | 2019-03-15 10:29:47 -0700 | [diff] [blame] | 36 | |
| 37 | virtual const char* what() const noexcept override |
| 38 | { |
| 39 | return _message.c_str(); |
| 40 | } |
| 41 | |
| 42 | 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 |