Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdexcept> |
| 4 | |
| 5 | namespace 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 | */ |
| 13 | class 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 | */ |
| 53 | class 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 | */ |
| 78 | class 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 | |
| 98 | class 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 | */ |
| 139 | class 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 | |
| 157 | } // namespace vpd |