blob: ec9d7a664ed472e2a7e6f2c1754442e9e9bc1944 [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 WriteVerificationError
26 *
27 * An error that occurred when performing a read after a write to ensure the
28 * write was successful.
29 *
30 * This exception is thrown when the value read is different than the value
31 * written. This is also known as a readback error.
32 */
33class WriteVerificationError : public std::exception
34{
35 public:
36 // Specify which compiler-generated methods we want
37 WriteVerificationError() = delete;
38 WriteVerificationError(const WriteVerificationError&) = default;
39 WriteVerificationError(WriteVerificationError&&) = default;
40 WriteVerificationError& operator=(const WriteVerificationError&) = default;
41 WriteVerificationError& operator=(WriteVerificationError&&) = default;
42 virtual ~WriteVerificationError() = default;
43
44 /**
45 * Constructor.
46 *
47 * @param error error message
48 */
49 explicit WriteVerificationError(const std::string& error) :
50 error{"WriteVerificationError: " + error}
51 {
52 }
53
54 /**
55 * Returns the description of this error.
56 *
57 * @return error description
58 */
59 const char* what() const noexcept override
60 {
61 return error.c_str();
62 }
63
64 private:
65 /**
66 * Error message.
67 */
68 const std::string error{};
69};
70
71} // namespace phosphor::power::regulators