blob: bcfd3666285f15f92d482697b5c58684d7fef8ed [file] [log] [blame]
SunnySrivastava19849d4f1122020-08-26 02:41:46 -05001#pragma once
2
3#include <stdexcept>
4
5namespace openpower
6{
7namespace vpd
8{
9namespace exceptions
10{
11
12/** @class VPDException
13 * @brief This class inherits std::runtime_error and overrrides
14 * "what" method to return the description of exception.
15 * This class also works as base class for custom exception
16 * classes of openpower-vpd repository.
17 */
18class VPDException : public std::runtime_error
19{
20 public:
21 // deleted methods
22 VPDException() = delete;
23 VPDException(const VPDException&) = delete;
24 VPDException(VPDException&&) = delete;
25 VPDException& operator=(const VPDException&) = delete;
26
27 // default destructor
28 ~VPDException() = default;
29
30 /** @brief constructor
31 * @param[in] - string to define exception
32 */
33 explicit VPDException(const std::string& msg) :
34 std::runtime_error(msg), errMsg(msg)
Patrick Williamsc78d8872023-05-10 07:50:56 -050035 {}
SunnySrivastava19849d4f1122020-08-26 02:41:46 -050036
37 /** @brief inline method to return exception string
38 * This is overridden method of std::runtime class
39 */
40 inline const char* what() const noexcept override
41 {
42 return errMsg.c_str();
43 }
44
45 private:
46 /** @brief string to hold the reason of exception */
47 std::string errMsg;
48
49}; // class VPDException
50
51/** @class VpdEccException
52 * @brief This class extends Exceptions class and define
53 * type for ECC related exception in VPD
54 */
55class VpdEccException : public VPDException
56{
57 public:
58 // deleted methods
59 VpdEccException() = delete;
60 VpdEccException(const VpdEccException&) = delete;
61 VpdEccException(VpdEccException&&) = delete;
62 VpdEccException& operator=(const VpdEccException&) = delete;
63
64 // default destructor
65 ~VpdEccException() = default;
66
67 /** @brief constructor
68 * @param[in] - string to define exception
69 */
Patrick Williamsc78d8872023-05-10 07:50:56 -050070 explicit VpdEccException(const std::string& msg) : VPDException(msg) {}
SunnySrivastava19849d4f1122020-08-26 02:41:46 -050071
72}; // class VpdEccException
73
74/** @class VpdDataException
75 * @brief This class extends Exceptions class and define
76 * type for data related exception in VPD
77 */
78class VpdDataException : public VPDException
79{
80 public:
81 // deleted methods
82 VpdDataException() = delete;
83 VpdDataException(const VpdDataException&) = delete;
84 VpdDataException(VpdDataException&&) = delete;
85 VpdDataException& operator=(const VpdDataException&) = delete;
86
87 // default destructor
88 ~VpdDataException() = default;
89
90 /** @brief constructor
91 * @param[in] - string to define exception
92 */
Patrick Williamsc78d8872023-05-10 07:50:56 -050093 explicit VpdDataException(const std::string& msg) : VPDException(msg) {}
SunnySrivastava19849d4f1122020-08-26 02:41:46 -050094
95}; // class VpdDataException
96
97class VpdJsonException : public VPDException
98{
99 public:
100 // deleted methods
101 VpdJsonException() = delete;
102 VpdJsonException(const VpdJsonException&) = delete;
103 VpdJsonException(VpdDataException&&) = delete;
104 VpdJsonException& operator=(const VpdDataException&) = delete;
105
106 // default destructor
107 ~VpdJsonException() = default;
108
109 /** @brief constructor
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500110 * @param[in] msg - string to define exception
111 * @param[in] path - Json path
SunnySrivastava19849d4f1122020-08-26 02:41:46 -0500112 */
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500113 VpdJsonException(const std::string& msg, const std::string& path) :
114 VPDException(msg), jsonPath(path)
Patrick Williamsc78d8872023-05-10 07:50:56 -0500115 {}
SunnySrivastava19849d4f1122020-08-26 02:41:46 -0500116
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500117 /** @brief Json path getter method.
118 * @return - Json path
119 */
SunnySrivastava19849d4f1122020-08-26 02:41:46 -0500120 inline std::string getJsonPath() const
121 {
122 return jsonPath;
123 }
124
125 private:
126 /** To hold the path of Json that failed to parse*/
127 std::string jsonPath;
128
129}; // class VpdJSonException
130
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500131/** @class GpioException
132 * @brief This class extends Exceptions class and define
133 * type for GPIO related exception in VPD
134 */
135class GpioException : public VPDException
136{
137 public:
138 // deleted methods
139 GpioException() = delete;
140 GpioException(const GpioException&) = delete;
141 GpioException(GpioException&&) = delete;
142 GpioException& operator=(const GpioException&) = delete;
143
144 // default destructor
145 ~GpioException() = default;
146
147 /** @brief constructor
148 * @param[in] msg - string to define exception
149 */
Patrick Williamsc78d8872023-05-10 07:50:56 -0500150 explicit GpioException(const std::string& msg) : VPDException(msg) {}
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500151};
152
SunnySrivastava19849d4f1122020-08-26 02:41:46 -0500153} // namespace exceptions
154} // namespace vpd
Patrick Williamsc78d8872023-05-10 07:50:56 -0500155} // namespace openpower