sdbus-c++  1.1.0
High-level C++ D-Bus library based on systemd D-Bus implementation
Error.h
Go to the documentation of this file.
1 
27 #ifndef SDBUS_CXX_ERROR_H_
28 #define SDBUS_CXX_ERROR_H_
29 
30 #include <errno.h>
31 #include <stdexcept>
32 #include <string>
33 
34 namespace sdbus {
35 
36  /********************************************/
42  class Error
43  : public std::runtime_error
44  {
45  public:
46  Error(const std::string& name, const std::string& message)
47  : std::runtime_error("[" + name + "] " + message)
48  , name_(name)
49  , message_(message)
50  {
51  }
52 
53  const std::string& getName() const
54  {
55  return name_;
56  }
57 
58  const std::string& getMessage() const
59  {
60  return message_;
61  }
62 
63  bool isValid() const
64  {
65  return !getName().empty();
66  }
67 
68  private:
69  std::string name_;
70  std::string message_;
71  };
72 
73  sdbus::Error createError(int errNo, const std::string& customMsg);
74 }
75 
76 #define SDBUS_THROW_ERROR(_MSG, _ERRNO) \
77  throw sdbus::createError((_ERRNO), (_MSG)) \
78 
79 
80 #define SDBUS_THROW_ERROR_IF(_COND, _MSG, _ERRNO) \
81  if (!(_COND)) ; else SDBUS_THROW_ERROR((_MSG), (_ERRNO)) \
82 
83 
84 #endif /* SDBUS_CXX_ERROR_H_ */
Definition: Error.h:44