27#ifndef SDBUS_CXX_ERROR_H_
28#define SDBUS_CXX_ERROR_H_
43 :
public std::runtime_error
47 class Name :
public std::string
51 explicit Name(std::string value)
52 : std::string(std::move(value))
54 explicit Name(
const char* value)
58 using std::string::operator=;
61 explicit Error(
Name name,
const char* message =
nullptr)
62 :
Error(std::move(name), std::string(message ? message :
""))
66 Error(Name name, std::string message)
67 : std::runtime_error(
"[" + name +
"] " + message)
68 , name_(std::move(name))
69 , message_(std::move(message))
73 [[nodiscard]]
const Name& getName()
const
78 [[nodiscard]]
const std::string& getMessage()
const
83 [[nodiscard]]
bool isValid()
const
85 return !getName().empty();
93 Error createError(
int errNo, std::string customMsg);
95 inline const Error::Name SDBUSCPP_ERROR_NAME{
"org.sdbuscpp.Error"};
98#define SDBUS_THROW_ERROR(_MSG, _ERRNO) \
99 throw sdbus::createError((_ERRNO), (_MSG)) \
102#define SDBUS_THROW_ERROR_IF(_COND, _MSG, _ERRNO) \
103 if (!(_COND)) ; else SDBUS_THROW_ERROR((_MSG), (_ERRNO)) \