blob: 2ea2cd5895633157bb3b4838f463480b4b3df309 [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)
35 {
36 }
37
38 /** @brief inline method to return exception string
39 * This is overridden method of std::runtime class
40 */
41 inline const char* what() const noexcept override
42 {
43 return errMsg.c_str();
44 }
45
46 private:
47 /** @brief string to hold the reason of exception */
48 std::string errMsg;
49
50}; // class VPDException
51
52/** @class VpdEccException
53 * @brief This class extends Exceptions class and define
54 * type for ECC related exception in VPD
55 */
56class VpdEccException : public VPDException
57{
58 public:
59 // deleted methods
60 VpdEccException() = delete;
61 VpdEccException(const VpdEccException&) = delete;
62 VpdEccException(VpdEccException&&) = delete;
63 VpdEccException& operator=(const VpdEccException&) = delete;
64
65 // default destructor
66 ~VpdEccException() = default;
67
68 /** @brief constructor
69 * @param[in] - string to define exception
70 */
71 explicit VpdEccException(const std::string& msg) : VPDException(msg)
72 {
73 }
74
75}; // class VpdEccException
76
77/** @class VpdDataException
78 * @brief This class extends Exceptions class and define
79 * type for data related exception in VPD
80 */
81class VpdDataException : public VPDException
82{
83 public:
84 // deleted methods
85 VpdDataException() = delete;
86 VpdDataException(const VpdDataException&) = delete;
87 VpdDataException(VpdDataException&&) = delete;
88 VpdDataException& operator=(const VpdDataException&) = delete;
89
90 // default destructor
91 ~VpdDataException() = default;
92
93 /** @brief constructor
94 * @param[in] - string to define exception
95 */
96 explicit VpdDataException(const std::string& msg) : VPDException(msg)
97 {
98 }
99
100}; // class VpdDataException
101
102class VpdJsonException : public VPDException
103{
104 public:
105 // deleted methods
106 VpdJsonException() = delete;
107 VpdJsonException(const VpdJsonException&) = delete;
108 VpdJsonException(VpdDataException&&) = delete;
109 VpdJsonException& operator=(const VpdDataException&) = delete;
110
111 // default destructor
112 ~VpdJsonException() = default;
113
114 /** @brief constructor
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500115 * @param[in] msg - string to define exception
116 * @param[in] path - Json path
SunnySrivastava19849d4f1122020-08-26 02:41:46 -0500117 */
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500118 VpdJsonException(const std::string& msg, const std::string& path) :
119 VPDException(msg), jsonPath(path)
SunnySrivastava19849d4f1122020-08-26 02:41:46 -0500120 {
121 }
122
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500123 /** @brief Json path getter method.
124 * @return - Json path
125 */
SunnySrivastava19849d4f1122020-08-26 02:41:46 -0500126 inline std::string getJsonPath() const
127 {
128 return jsonPath;
129 }
130
131 private:
132 /** To hold the path of Json that failed to parse*/
133 std::string jsonPath;
134
135}; // class VpdJSonException
136
137} // namespace exceptions
138} // namespace vpd
139} // namespace openpower