xref: /openbmc/phosphor-inventory-manager/errors.hpp (revision 0237971c1e8cd102e2035f92f8e794b8e6711b2d)
1 #pragma once
2 
3 #include <stdexcept>
4 
5 namespace phosphor
6 {
7 namespace inventory
8 {
9 namespace manager
10 {
11 
12 // TODO: Use proper error generation techniques
13 // https://github.com/openbmc/openbmc/issues/1125
14 
15 /** @class InterfaceError
16  *  @brief Exception class for unrecognized interfaces.
17  */
18 class InterfaceError final : public std::invalid_argument
19 {
20     public:
21         ~InterfaceError() = default;
22         InterfaceError() = delete;
23         InterfaceError(const InterfaceError&) = delete;
24         InterfaceError(InterfaceError&&) = default;
25         InterfaceError& operator=(const InterfaceError&) = delete;
26         InterfaceError& operator=(InterfaceError&&) = default;
27 
28         /** @brief Construct an interface error.
29          *
30          *  @param[in] msg - The message to be returned by what().
31          *  @param[in] iface - The failing interface name.
32          */
33         InterfaceError(
34             const char* msg,
35             const std::string& iface) :
36             std::invalid_argument(msg),
37             interface(iface) {}
38 
39         /** @brief Log the exception message to the systemd journal. */
40         void log() const;
41 
42     private:
43 
44         std::string interface;
45 };
46 
47 } // namespace manager
48 } // namespace inventory
49 } // namespace phosphor
50 
51 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
52