From 009d9aee0c67f7ce22f0f453579307677f018b15 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Mon, 27 Mar 2023 14:43:29 +0900 Subject: [PATCH] Add create_directories() exception handling 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 --- src/launchpad-process-pool/file_monitor.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/launchpad-process-pool/file_monitor.cc b/src/launchpad-process-pool/file_monitor.cc index 01d0e1f..27c9d80 100644 --- a/src/launchpad-process-pool/file_monitor.cc +++ b/src/launchpad-process-pool/file_monitor.cc @@ -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; } } -- 2.7.4