blob: 1db59c3b3cda9861b528e69070b984922765f96f [file] [log] [blame]
Willy Tua2056e92021-10-10 13:36:16 -07001// 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 Ventured2037c62019-03-15 10:29:47 -070015#pragma once
16
17#include <exception>
18#include <string>
19
20namespace google
21{
22namespace 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 */
29class 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 Williams444b5ea2023-05-19 13:56:42 -050035 {}
Patrick Ventured2037c62019-03-15 10:29:47 -070036
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