[coverity] resolve exception handle issue
authorhyeonseok <hs89.lee@samsung.com>
Thu, 6 Feb 2025 10:15:48 +0000 (19:15 +0900)
committerjijoong.moon <jijoong.moon@samsung.com>
Tue, 11 Feb 2025 05:45:59 +0000 (14:45 +0900)
 - Resolve exception handle issue by adding try catch statement
 - Remove noexcept

Signed-off-by: hyeonseok <hs89.lee@samsung.com>
Applications/TransferLearning/CIFAR_Classification/jni/main.cpp
api/ccapi/include/layer.h
nntrainer/graph/graph_node.h
nntrainer/layers/layer_node.cpp
nntrainer/layers/layer_node.h
nntrainer/nntrainer_logger.cpp

index 1d4d577910508321e69c69312913988761b5ac60..5971ef50757f2c38ad97884ae7b1d2dfa5683056 100644 (file)
@@ -393,7 +393,12 @@ int main(int argc, char *argv[]) {
      */
     std::string filename = data_path + "trainingSet.dat";
     std::ofstream f(filename, std::ios::out | std::ios::binary);
-    ExtractFeatures(data_path, inputVector, outputVector, "training", f);
+    try {
+      ExtractFeatures(data_path, inputVector, outputVector, "training", f);
+    } catch (...) {
+      std::cerr << "Error during open file: " << filename << std::endl;
+      return 1;
+    }
     f.close();
   }
 
@@ -403,7 +408,12 @@ int main(int argc, char *argv[]) {
      */
     std::string filename = data_path + "valSet.dat";
     std::ofstream f(filename, std::ios::out | std::ios::binary);
-    ExtractFeatures(data_path, inputValVector, outputValVector, "val", f);
+    try {
+      ExtractFeatures(data_path, inputValVector, outputValVector, "val", f);
+    } catch (...) {
+      std::cerr << "Error during open file: " << filename << std::endl;
+      return 1;
+    }
     f.close();
   }
 
@@ -413,7 +423,12 @@ int main(int argc, char *argv[]) {
      */
     std::string filename = data_path + "testSet.dat";
     std::ofstream f(filename, std::ios::out | std::ios::binary);
-    ExtractFeatures(data_path, inputTestVector, outputTestVector, "test", f);
+    try {
+      ExtractFeatures(data_path, inputTestVector, outputTestVector, "test", f);
+    } catch (...) {
+      std::cerr << "Error during open file: " << filename << std::endl;
+      return 1;
+    }
     f.close();
   }
 
index 3740500aa6ff7e18d817489309a4771016fa1b08..1482510e7c2a4d77d70328987cbd1a247f5a2b16 100644 (file)
@@ -193,7 +193,7 @@ public:
    * @note      This name might be changed once this layer is added to the model
    * to keep the name unique to the model
    */
-  virtual const std::string getName() const noexcept = 0;
+  virtual const std::string getName() const = 0;
 
   /**
    * @brief Get the Weight object name
index 8b8d4f8eb752bf7618a2ecfc3fd04ba68ad7df8a..5c79be5e092b86c973f4596c22ffb18d8c8bf3fd 100644 (file)
@@ -53,7 +53,7 @@ public:
    * @return std::string Name of the underlying object
    * @note name of each node in the graph must be unique
    */
-  virtual const std::string getName() const noexcept = 0;
+  virtual const std::string getName() const = 0;
 
   /**
    * @brief     Set the Name of the underlying object
index 36563b6570c716945c406dc42058f58930355c2a..535a8796244ae154fc21db82ed318165326747d0 100644 (file)
@@ -282,7 +282,7 @@ void LayerNode::setComputeEngine(
   this->compute_engine = compute_engine;
 }
 
-const std::string LayerNode::getName() const noexcept {
+const std::string LayerNode::getName() const {
   auto &name = std::get<props::Name>(*layer_node_props);
   return name.empty() ? "" : name.get();
 }
index ccd8bb8be10c8cfab225e328c90b6bdac5b24d1b..0ddb2ded3dbff736ee3693bbe07f84e8d8cd22ad 100644 (file)
@@ -116,7 +116,7 @@ public:
    * @note      This name might be changed once this layer is added to the model
    * to keep the name unique to the model
    */
-  const std::string getName() const noexcept override;
+  const std::string getName() const override;
 
   /**
    * Support all the interface requirements by nntrainer::GraphNode
index fd3ea2c7f9c5f979217df6eee9abe081b59317ba..d089ce7ab6b554acf3d83c473bebe8006598bf77 100644 (file)
@@ -65,7 +65,13 @@ Logger::Cleanup::~Cleanup() {
   Logger::ainstance = nullptr;
 }
 
-Logger::~Logger() { outputstream.close(); }
+Logger::~Logger() {
+  try {
+    outputstream.close();
+  } catch(...) {
+    std::cerr << "Error closing the log file\n";
+  }
+}
 
 Logger::Logger() : ts_type(NNTRAINER_LOG_TIMESTAMP_SEC) {
   struct tm now;