This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/simplify-cxx-exceptions
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 9fd85c9fac44062eb627ab2fe3abc8963b142a42
Author: Pepijn Noltes <[email protected]>
AuthorDate: Sun Jun 4 18:59:45 2023 +0200

    Move celix::Exception to utils and refactor to use using ctor
---
 .../celix/{Exception.h => FrameworkExceptions.h}   | 26 +++++++++-------------
 libs/framework/include/celix/ServiceRegistration.h |  6 ++---
 libs/framework/include/celix/Trackers.h            | 13 +++++------
 .../{framework => utils}/include/celix/Exception.h | 17 +++-----------
 libs/utils/include/celix/Filter.h                  | 16 +++----------
 5 files changed, 26 insertions(+), 52 deletions(-)

diff --git a/libs/framework/include/celix/Exception.h 
b/libs/framework/include/celix/FrameworkExceptions.h
similarity index 63%
copy from libs/framework/include/celix/Exception.h
copy to libs/framework/include/celix/FrameworkExceptions.h
index 87350b39..d6fd2cda 100644
--- a/libs/framework/include/celix/Exception.h
+++ b/libs/framework/include/celix/FrameworkExceptions.h
@@ -18,27 +18,23 @@
  */
 #pragma once
 
-#include <exception>
+#include "celix/Exception.h"
 
 namespace celix {
 
     /**
-     * @brief Celix runtime Exception
+     * @brief Celix Service Registration Exception
      */
-    class Exception : public std::exception {
+    class ServiceRegistrationException : public ::celix::Exception {
     public:
-        explicit Exception(std::string msg) : w{std::move(msg)} {}
-
-        Exception(const Exception&) = default;
-        Exception(Exception&&) = default;
-        Exception& operator=(const Exception&) = default;
-        Exception& operator=(Exception&&) = default;
-
-        const char* what() const noexcept override {
-            return w.c_str();
-        }
-    private:
-        std::string w;
+      using celix::Exception::Exception;
     };
 
+    /**
+     * @brief Celix Tracker Exception
+     */
+    class TrackerException : public ::celix::Exception {
+    public:
+        using celix::Exception::Exception;
+    };
 }
diff --git a/libs/framework/include/celix/ServiceRegistration.h 
b/libs/framework/include/celix/ServiceRegistration.h
index 6f7b4f0a..73b56c50 100644
--- a/libs/framework/include/celix/ServiceRegistration.h
+++ b/libs/framework/include/celix/ServiceRegistration.h
@@ -24,9 +24,9 @@
 #include <vector>
 #include <functional>
 
+#include "celix/FrameworkExceptions.h"
 #include "celix/Constants.h"
 #include "celix/Properties.h"
-#include "celix/Exception.h"
 #include "celix_bundle_context.h"
 #include "celix_bundle.h"
 #include "celix_framework.h"
@@ -338,12 +338,12 @@ namespace celix {
                 std::lock_guard<std::mutex> lck{mutex};
                 svcId = 
celix_bundleContext_registerServiceWithOptionsAsync(cCtx.get(), &opts);
                 if (svcId < 0) {
-                    throw celix::Exception{"Cannot register service"};
+                    throw celix::ServiceRegistrationException{"Cannot register 
service"};
                 }
             } else /*sync*/ {
                 long localSvcId = 
celix_bundleContext_registerServiceWithOptions(cCtx.get(), &opts);
                 if (localSvcId < 0) {
-                    throw celix::Exception{"Cannot register service"};
+                    throw celix::ServiceRegistrationException{"Cannot register 
service"};
                 }
                 {
                     std::lock_guard<std::mutex> lck{mutex};
diff --git a/libs/framework/include/celix/Trackers.h 
b/libs/framework/include/celix/Trackers.h
index 4314b30d..a9372c56 100644
--- a/libs/framework/include/celix/Trackers.h
+++ b/libs/framework/include/celix/Trackers.h
@@ -29,15 +29,14 @@
 #include <thread>
 
 #include "celix_utils.h"
+#include "celix_bundle_context.h"
+#include "celix_framework.h"
+#include "celix/FrameworkExceptions.h"
 #include "celix/Properties.h"
 #include "celix/Utils.h"
 #include "celix/Bundle.h"
 #include "celix/Constants.h"
 #include "celix/Filter.h"
-#include "celix/Exception.h"
-#include "celix_bundle_context.h"
-#include "celix_framework.h"
-
 
 namespace celix {
 
@@ -244,7 +243,7 @@ namespace celix {
                 //NOTE assuming the opts already configured the callbacks
                 trkId = 
celix_bundleContext_trackServicesWithOptionsAsync(cCtx.get(), &opts);
                 if (trkId < 0) {
-                    throw celix::Exception{"Cannot open service tracker"};
+                    throw celix::TrackerException{"Cannot open service 
tracker"};
                 }
             }
         }
@@ -654,7 +653,7 @@ namespace celix {
                 //NOTE the opts already configured the callbacks
                 trkId = 
celix_bundleContext_trackBundlesWithOptionsAsync(cCtx.get(), &opts);
                 if (trkId < 0) {
-                    throw celix::Exception{"Cannot open bundle tracker"};
+                    throw celix::TrackerException{"Cannot open bundle 
tracker"};
                 }
             }
         }
@@ -821,7 +820,7 @@ namespace celix {
                             trk->state = TrackerState::OPEN;
                         });
                 if (trkId < 0) {
-                    throw celix::Exception{"Cannot open meta tracker"};
+                    throw celix::TrackerException{"Cannot open meta tracker"};
                 }
             }
         }
diff --git a/libs/framework/include/celix/Exception.h 
b/libs/utils/include/celix/Exception.h
similarity index 66%
rename from libs/framework/include/celix/Exception.h
rename to libs/utils/include/celix/Exception.h
index 87350b39..481d6f86 100644
--- a/libs/framework/include/celix/Exception.h
+++ b/libs/utils/include/celix/Exception.h
@@ -18,27 +18,16 @@
  */
 #pragma once
 
-#include <exception>
+#include <stdexcept>
 
 namespace celix {
 
     /**
      * @brief Celix runtime Exception
      */
-    class Exception : public std::exception {
+    class Exception : public std::runtime_error {
     public:
-        explicit Exception(std::string msg) : w{std::move(msg)} {}
-
-        Exception(const Exception&) = default;
-        Exception(Exception&&) = default;
-        Exception& operator=(const Exception&) = default;
-        Exception& operator=(Exception&&) = default;
-
-        const char* what() const noexcept override {
-            return w.c_str();
-        }
-    private:
-        std::string w;
+        using std::runtime_error::runtime_error;
     };
 
 }
diff --git a/libs/utils/include/celix/Filter.h 
b/libs/utils/include/celix/Filter.h
index f0a02d9f..836e0ff8 100644
--- a/libs/utils/include/celix/Filter.h
+++ b/libs/utils/include/celix/Filter.h
@@ -23,6 +23,7 @@
 #include <cstring>
 
 #include "celix_filter.h"
+#include "celix/Exception.h"
 #include "celix/Properties.h"
 
 namespace celix {
@@ -30,20 +31,9 @@ namespace celix {
     /**
      * @brief FilterException
      */
-    class FilterException : public std::exception {
+    class FilterException : public ::celix::Exception {
     public:
-        explicit FilterException(std::string msg) : w{std::move(msg)} {}
-
-        FilterException(const FilterException&) = default;
-        FilterException(FilterException&&) = default;
-        FilterException& operator=(const FilterException&) = default;
-        FilterException& operator=(FilterException&&) = default;
-
-        const char* what() const noexcept override {
-            return w.c_str();
-        }
-    private:
-        std::string w;
+        using celix::Exception::Exception;
     };
 
     /**

Reply via email to