sdbus-c++
1.2.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
explicit
Error
(
const
std::string& name,
const
char
* message =
nullptr
)
47
:
Error
(name, std::string(message ? message :
""
))
48
{
49
}
50
51
Error
(
const
std::string& name,
const
std::string& message)
52
: std::runtime_error(
"["
+ name +
"] "
+ message)
53
, name_(name)
54
, message_(message)
55
{
56
}
57
58
const
std::string& getName()
const
59
{
60
return
name_;
61
}
62
63
const
std::string& getMessage()
const
64
{
65
return
message_;
66
}
67
68
bool
isValid()
const
69
{
70
return
!getName().empty();
71
}
72
73
private
:
74
std::string name_;
75
std::string message_;
76
};
77
78
sdbus::Error
createError(
int
errNo,
const
std::string& customMsg);
79
}
80
81
#define SDBUS_THROW_ERROR(_MSG, _ERRNO) \
82
throw sdbus::createError((_ERRNO), (_MSG)) \
83
84
85
#define SDBUS_THROW_ERROR_IF(_COND, _MSG, _ERRNO) \
86
if (!(_COND)) ; else SDBUS_THROW_ERROR((_MSG), (_ERRNO)) \
87
88
89
#endif
/* SDBUS_CXX_ERROR_H_ */
sdbus::Error
Definition:
Error.h:44
sdbus-cpp
include
sdbus-c++
Error.h
Generated by
1.9.3