Fix ML task un-catched error
authorKwanghoon Son <k.son@samsung.com>
Wed, 24 Apr 2024 10:05:34 +0000 (10:05 +0000)
committerKwanghoon Son <k.son@samsung.com>
Mon, 24 Jun 2024 03:53:24 +0000 (03:53 +0000)
In the case of EngineConfig, if there is no json file, the int type is
throw. But BaseException cannot catch it.

So changing the int type to runtime_error and add catch that can catch
all errors.

Change-Id: I7c073ddbd22aa649982a51909370f1c8e3be54ae
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
mv_common/src/EngineConfig.cpp
mv_machine_learning/face_recognition/src/mv_face_recognition.cpp
mv_machine_learning/image_classification/src/mv_image_classification.cpp
mv_machine_learning/image_segmentation/src/mv_selfie_segmentation.cpp
mv_machine_learning/landmark_detection/src/mv_facial_landmark.cpp
mv_machine_learning/landmark_detection/src/mv_pose_landmark.cpp
mv_machine_learning/object_detection/src/mv_object_detection.cpp
mv_machine_learning/object_detection_3d/src/mv_object_detection_3d.cpp

index 895b3a911eece10795de9bf5f4858f730f9354ff..a5b8760d389d1e75e50a3596b115a0916f439dfc 100644 (file)
@@ -19,7 +19,7 @@
 #include <mv_private.h>
 
 #include <json-glib/json-glib.h>
-
+#include <stdexcept>
 /**
  * @file   EngineConfig.cpp
  * @brief  Engine Configuration class methods implementation.
@@ -36,7 +36,7 @@ EngineConfig::EngineConfig(std::string config_file_path)
        /* Force load default attributes from configuration file */
        int ret = loadDictionaries(config_file_path);
        if (ret != MEDIA_VISION_ERROR_NONE)
-               throw static_cast<int>(ret);
+               throw std::runtime_error("Failed to loadDictionaries");
 }
 
 EngineConfig::~EngineConfig()
index 8f21dd1f0f1ae18d9d54a01993998429714f3259..66a4d0da4694e06740618d631bd8ea2e7dcb526b 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <algorithm>
 #include <dlog.h>
+#include <exception>
 #include <memory>
 #include <mutex>
 
@@ -59,6 +60,9 @@ int mv_face_recognition_create(mv_face_recognition_h *out_handle)
                machine_learning_native_add(ctx, "facenet", new FacenetAdapter());
        } catch (const BaseException &e) {
                return e.getError();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
        }
 
        *out_handle = ctx;
index 18e2583add307ea2ed09435addeb1c6f1c2d02dd..b14f2168f00db40e4915fdab58a9905b2cbc0f14 100644 (file)
@@ -26,6 +26,7 @@
 #include "native_capi.h"
 
 #include <algorithm>
+#include <exception>
 #include <new>
 #include <string>
 #include <unistd.h>
@@ -58,6 +59,9 @@ int mv_image_classification_create(mv_image_classification_h *out_handle)
        } catch (const BaseException &e) {
                LOGE("%s", e.what());
                return e.getError();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
        }
 
        *out_handle = ctx;
index f9e366af9935eb786d4665c20be7e2b6b5d1aba0..75b2ecf5dc479d45e084d1fd354751e1cca38638 100644 (file)
@@ -26,6 +26,7 @@
 #include "native_capi.h"
 
 #include <algorithm>
+#include <exception>
 #include <iostream>
 #include <mutex>
 #include <new>
@@ -60,6 +61,9 @@ int mv_selfie_segmentation_create(mv_selfie_segmentation_h *handle)
        } catch (const BaseException &e) {
                LOGE("%s", e.what());
                return e.getError();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
        }
 
        *handle = ctx;
index b2acf479270dc15dfa20d28777c9ef2cd4d8de72..67c2bc524753734fc324c704e1f3c06b26e27dcf 100644 (file)
@@ -26,6 +26,7 @@
 #include "native_capi.h"
 
 #include <algorithm>
+#include <exception>
 #include <new>
 #include <string>
 #include <unistd.h>
@@ -58,6 +59,9 @@ int mv_facial_landmark_create(mv_facial_landmark_h *handle)
        } catch (const BaseException &e) {
                LOGE("%s", e.what());
                return e.getError();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
        }
 
        *handle = ctx;
index aa4190741ec4ee4e0b6641261ed96232eb76a1c3..e29551d5e735edb06847c36c98652800eb73e1a1 100644 (file)
@@ -26,6 +26,7 @@
 #include "native_capi.h"
 
 #include <algorithm>
+#include <exception>
 #include <new>
 #include <string>
 #include <unistd.h>
@@ -58,6 +59,9 @@ int mv_pose_landmark_create(mv_pose_landmark_h *handle)
        } catch (const BaseException &e) {
                LOGE("%s", e.what());
                return e.getError();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
        }
 
        *handle = ctx;
index cd2c02c0225a15f12ceea53bfe3cfa33074219c5..a9134e2630caf880b2d09744610d595542e3d33d 100644 (file)
@@ -26,6 +26,7 @@
 #include "object_detection_type.h"
 
 #include <algorithm>
+#include <exception>
 #include <iostream>
 #include <mutex>
 #include <new>
@@ -59,6 +60,9 @@ int mv_object_detection_create(mv_object_detection_h *handle)
                machine_learning_native_add(ctx, TASK_NAME, new ObjectDetectionAdapter());
        } catch (const BaseException &e) {
                return e.getError();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
        }
 
        *handle = ctx;
index 74192469503b98f17f527276b6d0ada1a0821111..6641376e26cb35496765ed28616b82987ce92fe0 100644 (file)
@@ -25,6 +25,7 @@
 #include "object_detection_3d_type.h"
 
 #include <algorithm>
+#include <exception>
 #include <mutex>
 #include <new>
 #include <string>
@@ -60,6 +61,9 @@ int mv_object_detection_3d_create(mv_object_detection_3d_h *handle)
        } catch (const BaseException &e) {
                LOGE("%s", e.what());
                return e.getError();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
        }
 
        *handle = ctx;