sdbus-c++
2.3.1
High-level C++ D-Bus library based on systemd D-Bus implementation
Toggle main menu visibility
Loading...
Searching...
No Matches
Error.h
Go to the documentation of this file.
1
26
27
#ifndef SDBUS_CXX_ERROR_H_
28
#define SDBUS_CXX_ERROR_H_
29
30
#include <cerrno>
31
#include <stdexcept>
32
#include <string>
33
34
namespace
sdbus {
35
36
/********************************************/
42
class
Error
43
:
public
std::runtime_error
44
{
45
public
:
46
// Strong type representing the D-Bus error name
47
class
Name :
public
std::string
48
{
49
public
:
50
Name() =
default
;
51
explicit
Name(std::string value)
52
: std::string(std::move(value))
53
{}
54
explicit
Name(
const
char
* value)
55
: std::string(value)
56
{}
57
58
using
std::string::operator=;
59
};
60
61
explicit
Error(
Name
name,
const
char
* message =
nullptr
)
62
: Error(std::move(name), std::string(message ? message :
""
))
63
{
64
}
65
66
Error
(Name name, std::string message)
67
: std::runtime_error(!message.empty() ?
"["
+ name +
"] "
+ message :
"["
+ name +
"]"
)
68
, name_(std::move(name))
69
, message_(std::move(message))
70
{
71
}
72
73
[[nodiscard]]
const
Name& getName()
const
74
{
75
return
name_;
76
}
77
78
[[nodiscard]]
const
std::string& getMessage()
const
79
{
80
return
message_;
81
}
82
83
[[nodiscard]]
bool
isValid()
const
84
{
85
return
!getName().empty();
86
}
87
88
private
:
89
Name
name_;
90
std::string message_;
91
};
92
93
Error
createError(
int
errNo, std::string customMsg = {});
94
95
inline
const
Error::Name
SDBUSCPP_ERROR_NAME{
"org.sdbuscpp.Error"
};
96
}
// namespace sdbus
97
98
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
99
#define SDBUS_THROW_ERROR(_MSG, _ERRNO) \
100
throw sdbus::createError((_ERRNO), (_MSG)) \
101
/**/
102
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
103
#define SDBUS_THROW_ERROR_IF(_COND, _MSG, _ERRNO) \
104
if (!(_COND)) ; else SDBUS_THROW_ERROR((_MSG), (_ERRNO)) \
105
/**/
106
107
#endif
/* SDBUS_CXX_ERROR_H_ */
sdbus::Error::Name
Definition
Error.h:48
sdbus::Error
Definition
Error.h:44
include
sdbus-c++
Error.h
Generated by
1.17.0