exception: create subclass for generated errors
All errors generated by sdbus++ YAML we want to follow the systemd
default errno value (EIO). All exceptions defined otherwise it is
probably a good idea to ensure that the author picks an explicit
errno.
Create a base class for generated exceptions to hold the default
`get_errno() { return EIO; }` implementation, which can be used by
various repositories and later turn the exception_t one into a pure
virtual.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I2648825b677353970eed4724bd2d3710a103d814
diff --git a/include/sdbusplus/exception.hpp b/include/sdbusplus/exception.hpp
index 90e735e..65f85c1 100644
--- a/include/sdbusplus/exception.hpp
+++ b/include/sdbusplus/exception.hpp
@@ -22,6 +22,12 @@
virtual int get_errno() const noexcept;
};
+/** base exception class for all errors created by the sdbus++ generator */
+struct generated_exception : public exception
+{
+ int get_errno() const noexcept override;
+};
+
/** base exception class for all errors generated by sdbusplus itself. */
struct internal_exception : public exception
{};
diff --git a/src/exception.cpp b/src/exception.cpp
index 640454a..4fa5135 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -19,6 +19,11 @@
return EIO;
}
+int generated_exception::get_errno() const noexcept
+{
+ return EIO;
+}
+
SdBusError::SdBusError(int error, const char* prefix, SdBusInterface* intf) :
error(SD_BUS_ERROR_NULL), intf(intf)
{
diff --git a/tools/sdbusplus/templates/error.hpp.mako b/tools/sdbusplus/templates/error.hpp.mako
index a64eac0..8ef5da3 100644
--- a/tools/sdbusplus/templates/error.hpp.mako
+++ b/tools/sdbusplus/templates/error.hpp.mako
@@ -12,7 +12,8 @@
{
% for e in error.errors:
-struct ${e.name} final : public sdbusplus::exception_t
+struct ${e.name} final :
+ public sdbusplus::exception::generated_exception
{
static constexpr auto errName = "${error.name}.Error.${e.name}";
static constexpr auto errDesc =