Patrick Williams | f4a6f41 | 2016-11-11 13:47:29 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <exception> |
| 4 | |
| 5 | namespace sdbusplus |
| 6 | { |
| 7 | |
| 8 | namespace exception |
| 9 | { |
| 10 | |
Patrick Williams | 1a28306 | 2016-11-13 19:05:10 -0600 | [diff] [blame] | 11 | /** Base exception class for all sdbusplus exceptions, including those created |
| 12 | * by the bindings. */ |
Patrick Williams | f4a6f41 | 2016-11-11 13:47:29 -0600 | [diff] [blame] | 13 | struct exception : public std::exception |
| 14 | { |
Patrick Williams | ea24144 | 2016-11-15 14:41:13 -0600 | [diff] [blame] | 15 | virtual const char* name() const noexcept = 0; |
| 16 | virtual const char* description() const noexcept = 0; |
Patrick Williams | f4a6f41 | 2016-11-11 13:47:29 -0600 | [diff] [blame] | 17 | }; |
| 18 | |
Patrick Williams | 1a28306 | 2016-11-13 19:05:10 -0600 | [diff] [blame] | 19 | /** base exception class for all errors generated by sdbusplus itself. */ |
| 20 | struct internal_exception : public exception |
| 21 | { |
| 22 | }; |
| 23 | |
Patrick Williams | 59b70d1 | 2016-11-16 16:11:25 -0600 | [diff] [blame] | 24 | /** Exception for when an invalid conversion from string to enum is |
| 25 | * attempted. */ |
| 26 | struct InvalidEnumString final : public internal_exception |
| 27 | { |
| 28 | static constexpr auto errName = |
Patrick Williams | 02d9675 | 2017-04-19 07:52:29 -0500 | [diff] [blame] | 29 | "xyz.openbmc_project.sdbusplus.Error.InvalidEnumString"; |
Patrick Williams | 59b70d1 | 2016-11-16 16:11:25 -0600 | [diff] [blame] | 30 | static constexpr auto errDesc = |
| 31 | "An enumeration mapping was attempted for which no valid enumeration " |
| 32 | "value exists."; |
| 33 | static constexpr auto errWhat = |
Patrick Williams | 02d9675 | 2017-04-19 07:52:29 -0500 | [diff] [blame] | 34 | "xyz.openbmc_project.sdbusplus.Error.InvalidEnumString: " |
Patrick Williams | 59b70d1 | 2016-11-16 16:11:25 -0600 | [diff] [blame] | 35 | "An enumeration mapping was attempted for which no valid enumeration " |
| 36 | "value exists."; |
| 37 | |
Patrick Williams | 93b0e70 | 2017-04-18 11:19:45 -0500 | [diff] [blame] | 38 | const char* name() const noexcept override; |
| 39 | const char* description() const noexcept override; |
| 40 | const char* what() const noexcept override; |
Patrick Williams | 59b70d1 | 2016-11-16 16:11:25 -0600 | [diff] [blame] | 41 | }; |
| 42 | |
Patrick Williams | f4a6f41 | 2016-11-11 13:47:29 -0600 | [diff] [blame] | 43 | } // namespace exception |
| 44 | |
| 45 | using exception_t = exception::exception; |
Patrick Williams | 1a28306 | 2016-11-13 19:05:10 -0600 | [diff] [blame] | 46 | using internal_exception_t = exception::internal_exception; |
Patrick Williams | f4a6f41 | 2016-11-11 13:47:29 -0600 | [diff] [blame] | 47 | |
| 48 | } // namespace sdbusplus |