Use tizen_base::Exception class to throw exceptions
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 7 Apr 2025 23:46:20 +0000 (08:46 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 7 Apr 2025 23:46:20 +0000 (08:46 +0900)
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/service.cc
src/service_loader.cc

index 975f766614074b339e6eb7b27a2e89791ef3a746..217233a78c01cb7ae59d59091db50c079e82b69e 100644 (file)
 
 #include <tizen_core.h>
 
-#include <utility>
 #include <stdexcept>
+#include <utility>
 
+#include "exception.hh"
 #include "log_private.hh"
 #include "service_manager.hh"
 
@@ -31,7 +32,7 @@ Service::Service(std::shared_ptr<ServiceInfo> info,
     : info_(std::move(info)), listener_(std::move(listener)) {
   if (!Init()) {
     Shutdown();
-    throw new std::runtime_error("Failed to initialize service");
+    THROW(SERVICE_ERROR_INVALID_CONTEXT);
   }
 
   ServiceManager::GetInst().NotifyServiceStateChanged(this);
@@ -127,7 +128,7 @@ void Service::Run() {
   int ret = tizen_core_task_run(task_);
   if (ret != TIZEN_CORE_ERROR_NONE) {
     _E("tizen_core_task_run() is failed");
-    throw new std::runtime_error("Failed to run service");
+    THROW(SERVICE_ERROR_INVALID_CONTEXT);
   }
   running_ = true;
 }
@@ -165,7 +166,7 @@ void Service::SendMessage(const tizen_base::Bundle& envelope) {
   tizen_core_channel_object_destroy(object);
   if (ret != TIZEN_CORE_ERROR_NONE) {
     _E("tizen_core_channel_send() is failed. error=%d", ret);
-    throw new std::runtime_error("Failed to send message");
+    THROW(SERVICE_ERROR_IO_ERROR);
   }
 }
 
index 29e5c7e727c88266ba0712e6bf613ab075cae626..18efc7eab9460fb4a24ab9a447a5fad518ba7745 100644 (file)
@@ -41,7 +41,7 @@ ServiceLoader::ServiceLoader(int argc, char** argv, std::string name)
     : argc_(argc), argv_(argv), name_(std::move(name)) {
   if (!Init()) {
     Shutdown();
-    throw new std::runtime_error("Failed to initializer service loader");
+    THROW(SERVICE_ERROR_INVALID_CONTEXT);
   }
 }