blob: 12ab4eb3f4f74f60165121d263f099cd4748fac8 [file] [log] [blame]
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05001#pragma once
2
3#include <stdexcept>
4
5namespace vpd
6{
7/** @class Exception
8 * @brief This class inherits std::runtime_error and overrrides "what" method
9 * to return the description of exception.
10 * This class also works as base class for custom exception classes for
11 * VPD repository.
12 */
13class Exception : public std::runtime_error
14{
15 public:
16 // deleted methods
17 Exception() = delete;
18 Exception(const Exception&) = delete;
19 Exception(Exception&&) = delete;
20 Exception& operator=(const Exception&) = delete;
21
22 // default destructor
23 ~Exception() = default;
24
25 /** @brief constructor
26 *
27 * @param[in] msg - Information w.r.t exception.
28 */
29 explicit Exception(const std::string& msg) :
30 std::runtime_error(msg), m_errMsg(msg)
31 {}
32
33 /** @brief inline method to return exception string.
34 *
35 * This is overridden method of std::runtime class.
36 */
37 inline const char* what() const noexcept override
38 {
39 return m_errMsg.c_str();
40 }
41
42 private:
43 /** @brief string to hold the reason of exception */
44 std::string m_errMsg;
45
46}; // class Exception
47
48/** @class EccException
49 *
50 * @brief This class extends Exceptions class and define type for ECC related
51 * exception in VPD.
52 */
53class EccException : public Exception
54{
55 public:
56 // deleted methods
57 EccException() = delete;
58 EccException(const EccException&) = delete;
59 EccException(EccException&&) = delete;
60 EccException& operator=(const EccException&) = delete;
61
62 // default destructor
63 ~EccException() = default;
64
65 /** @brief constructor
66 *
67 * @param[in] msg - Information w.r.t exception.
68 */
69 explicit EccException(const std::string& msg) : Exception(msg) {}
70
71}; // class EccException
72
73/** @class DataException
74 *
75 * @brief This class extends Exceptions class and define type for data related
76 * exception in VPD
77 */
78class DataException : public Exception
79{
80 public:
81 // deleted methods
82 DataException() = delete;
83 DataException(const DataException&) = delete;
84 DataException(DataException&&) = delete;
85 DataException& operator=(const DataException&) = delete;
86
87 // default destructor
88 ~DataException() = default;
89
90 /** @brief constructor
91 *
92 * @param[in] msg - string to define exception
93 */
94 explicit DataException(const std::string& msg) : Exception(msg) {}
95
96}; // class DataException
97
98class JsonException : public Exception
99{
100 public:
101 // deleted methods
102 JsonException() = delete;
103 JsonException(const JsonException&) = delete;
104 JsonException(JsonException&&) = delete;
105 JsonException& operator=(const JsonException&) = delete;
106
107 // default destructor
108 ~JsonException() = default;
109
110 /** @brief constructor
111 * @param[in] msg - Information w.r.t. exception.
112 * @param[in] path - Json path
113 */
114 JsonException(const std::string& msg, const std::string& path) :
115 Exception(msg), m_jsonPath(path)
116 {}
117
118 /** @brief Json path getter method.
119 *
120 * @return - Json path
121 */
122 inline std::string getJsonPath() const
123 {
124 return m_jsonPath;
125 }
126
127 private:
128 /** To hold the path of Json that failed*/
129 std::string m_jsonPath;
130
131}; // class JSonException
132
133/** @class GpioException
134 * @brief Custom handler for GPIO exception.
135 *
136 * This class extends Exceptions class and define
137 * type for GPIO related exception in VPD.
138 */
139class GpioException : public Exception
140{
141 public:
142 // deleted methods
143 GpioException() = delete;
144 GpioException(const GpioException&) = delete;
145 GpioException(GpioException&&) = delete;
146 GpioException& operator=(const GpioException&) = delete;
147
148 // default destructor
149 ~GpioException() = default;
150
151 /** @brief constructor
152 * @param[in] msg - string to define exception
153 */
154 explicit GpioException(const std::string& msg) : Exception(msg) {}
155};
156
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530157/** @class DbusException
158 * @brief Custom handler for Dbus exception.
159 *
160 * This class extends Exceptions class and define
161 * type for DBus related exception in VPD.
162 */
163class DbusException : public Exception
164{
165 public:
166 // deleted methods
167 DbusException() = delete;
168 DbusException(const DbusException&) = delete;
169 DbusException(DbusException&&) = delete;
170 DbusException& operator=(const DbusException&) = delete;
171
172 // default destructor
173 ~DbusException() = default;
174
175 /** @brief constructor
176 * @param[in] msg - string to define exception
177 */
178 explicit DbusException(const std::string& msg) : Exception(msg) {}
179};
180
181/** @class FirmwareException
182 * @brief Custom handler for firmware exception.
183 *
184 * This class extends Exceptions class and define
185 * type for generic firmware related exception in VPD.
186 */
187class FirmwareException : public Exception
188{
189 public:
190 // deleted methods
191 FirmwareException() = delete;
192 FirmwareException(const FirmwareException&) = delete;
193 FirmwareException(FirmwareException&&) = delete;
194 FirmwareException& operator=(const FirmwareException&) = delete;
195
196 // default destructor
197 ~FirmwareException() = default;
198
199 /** @brief constructor
200 * @param[in] msg - string to define exception
201 */
202 explicit FirmwareException(const std::string& msg) : Exception(msg) {}
203};
204
205/** @class EepromException
206 * @brief Custom handler for EEPROM exception.
207 *
208 * This class extends Exceptions class and define
209 * type for EEPROM related exception in VPD.
210 */
211class EepromException : public Exception
212{
213 public:
214 // deleted methods
215 EepromException() = delete;
216 EepromException(const EepromException&) = delete;
217 EepromException(EepromException&&) = delete;
218 EepromException& operator=(const EepromException&) = delete;
219
220 // default destructor
221 ~EepromException() = default;
222
223 /** @brief constructor
224 * @param[in] msg - string to define exception
225 */
226 explicit EepromException(const std::string& msg) : Exception(msg) {}
227};
228
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500229} // namespace vpd