Add create_directories() exception handling 67/290467/5
authorChanggyu Choi <changyu.choi@samsung.com>
Mon, 27 Mar 2023 05:43:29 +0000 (14:43 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 27 Mar 2023 06:10:53 +0000 (15:10 +0900)
std::filesystem::create_directories() can throw an exception.
This patch adds the exception handling for the above case.

Change-Id: I37228b7b38ae1c9894ae2b1586429c39e8379e63
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/launchpad-process-pool/file_monitor.cc

index 01d0e1f..27c9d80 100644 (file)
@@ -55,8 +55,15 @@ FileMonitor::FileMonitor(const std::string_view file_path,
   parent_path_ = path.parent_path();
   file_name_ = path.filename();
   if (!fs::exists(parent_path_)) {
-    if (!fs::create_directories(parent_path_)) {
-      _E("Failed to create directory. %s", parent_path_.c_str());
+    try {
+      if (!fs::create_directories(parent_path_)) {
+        _E("Failed to create directory. %s", parent_path_.c_str());
+        disposed_ = true;
+        return;
+      }
+    } catch (const std::exception& e) {
+      _E("Exception has been occurred: %s", e.what());
+      disposed_ = true;
       return;
     }
   }