1 #pragma once
2 
3 #include <stdexcept>
4 
5 namespace openpower
6 {
7 namespace vpd
8 {
9 namespace 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  */
18 class 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  */
56 class 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  */
81 class 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 
102 class 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
115      *  @param[in] msg - string to define exception
116      *  @param[in] path - Json path
117      */
118     VpdJsonException(const std::string& msg, const std::string& path) :
119         VPDException(msg), jsonPath(path)
120     {
121     }
122 
123     /** @brief Json path getter method.
124      *  @return - Json path
125      */
126     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