blob: b5895260679b42f8219692ec45f398acf617b8ba [file] [log] [blame]
Shawn McCarneya5ef5402020-03-01 16:29:44 -06001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <exception>
19#include <string>
20
21namespace phosphor::power::regulators
22{
23
24/**
25 * @class PMBusError
26 *
27 * An error that occurred while sending PMBus commands or converting data
28 * between PMBus formats.
29 */
30class PMBusError : public std::exception
31{
32 public:
33 // Specify which compiler-generated methods we want
34 PMBusError() = delete;
35 PMBusError(const PMBusError&) = default;
36 PMBusError(PMBusError&&) = default;
37 PMBusError& operator=(const PMBusError&) = default;
38 PMBusError& operator=(PMBusError&&) = default;
39 virtual ~PMBusError() = default;
40
41 /**
42 * Constructor.
43 *
44 * @param error error message
45 */
46 explicit PMBusError(const std::string& error) :
47 error{"PMBusError: " + error}
48 {
49 }
50
51 /**
52 * Returns the description of this error.
53 *
54 * @return error description
55 */
56 const char* what() const noexcept override
57 {
58 return error.c_str();
59 }
60
61 private:
62 /**
63 * Error message.
64 */
65 const std::string error{};
66};
67
68} // namespace phosphor::power::regulators