forked from ibm-openbmc/openpower-vpd-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpd_exceptions.hpp
155 lines (129 loc) · 3.99 KB
/
vpd_exceptions.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#pragma once
#include <stdexcept>
namespace openpower
{
namespace vpd
{
namespace exceptions
{
/** @class VPDException
* @brief This class inherits std::runtime_error and overrrides
* "what" method to return the description of exception.
* This class also works as base class for custom exception
* classes of openpower-vpd repository.
*/
class VPDException : public std::runtime_error
{
public:
// deleted methods
VPDException() = delete;
VPDException(const VPDException&) = delete;
VPDException(VPDException&&) = delete;
VPDException& operator=(const VPDException&) = delete;
// default destructor
~VPDException() = default;
/** @brief constructor
* @param[in] - string to define exception
*/
explicit VPDException(const std::string& msg) :
std::runtime_error(msg), errMsg(msg)
{}
/** @brief inline method to return exception string
* This is overridden method of std::runtime class
*/
inline const char* what() const noexcept override
{
return errMsg.c_str();
}
private:
/** @brief string to hold the reason of exception */
std::string errMsg;
}; // class VPDException
/** @class VpdEccException
* @brief This class extends Exceptions class and define
* type for ECC related exception in VPD
*/
class VpdEccException : public VPDException
{
public:
// deleted methods
VpdEccException() = delete;
VpdEccException(const VpdEccException&) = delete;
VpdEccException(VpdEccException&&) = delete;
VpdEccException& operator=(const VpdEccException&) = delete;
// default destructor
~VpdEccException() = default;
/** @brief constructor
* @param[in] - string to define exception
*/
explicit VpdEccException(const std::string& msg) : VPDException(msg) {}
}; // class VpdEccException
/** @class VpdDataException
* @brief This class extends Exceptions class and define
* type for data related exception in VPD
*/
class VpdDataException : public VPDException
{
public:
// deleted methods
VpdDataException() = delete;
VpdDataException(const VpdDataException&) = delete;
VpdDataException(VpdDataException&&) = delete;
VpdDataException& operator=(const VpdDataException&) = delete;
// default destructor
~VpdDataException() = default;
/** @brief constructor
* @param[in] - string to define exception
*/
explicit VpdDataException(const std::string& msg) : VPDException(msg) {}
}; // class VpdDataException
class VpdJsonException : public VPDException
{
public:
// deleted methods
VpdJsonException() = delete;
VpdJsonException(const VpdJsonException&) = delete;
VpdJsonException(VpdDataException&&) = delete;
VpdJsonException& operator=(const VpdDataException&) = delete;
// default destructor
~VpdJsonException() = default;
/** @brief constructor
* @param[in] msg - string to define exception
* @param[in] path - Json path
*/
VpdJsonException(const std::string& msg, const std::string& path) :
VPDException(msg), jsonPath(path)
{}
/** @brief Json path getter method.
* @return - Json path
*/
inline std::string getJsonPath() const
{
return jsonPath;
}
private:
/** To hold the path of Json that failed to parse*/
std::string jsonPath;
}; // class VpdJSonException
/** @class GpioException
* @brief This class extends Exceptions class and define
* type for GPIO related exception in VPD
*/
class GpioException : public VPDException
{
public:
// deleted methods
GpioException() = delete;
GpioException(const GpioException&) = delete;
GpioException(GpioException&&) = delete;
GpioException& operator=(const GpioException&) = delete;
// default destructor
~GpioException() = default;
/** @brief constructor
* @param[in] msg - string to define exception
*/
explicit GpioException(const std::string& msg) : VPDException(msg) {}
};
} // namespace exceptions
} // namespace vpd
} // namespace openpower