mv_machine_learning: add try-catch statement
authorInki Dae <inki.dae@samsung.com>
Wed, 20 Jul 2022 07:22:54 +0000 (16:22 +0900)
committerInki Dae <inki.dae@samsung.com>
Fri, 2 Sep 2022 08:09:25 +0000 (17:09 +0900)
[Issue type] bug fix

Added try-catch statement to mv_face_recognition_prepare_open function,
which was missed, printed out the error messages correctly.

Change-Id: I0753cda2b894c10033141f69a0a3e1d60eb303e7
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_machine_learning/face_recognition/src/mv_face_recognition_open.cpp

index 598aaae..9ac8351 100644 (file)
@@ -98,11 +98,16 @@ int mv_face_recognition_prepare_open(mv_face_recognition_h handle)
                return MEDIA_VISION_ERROR_INVALID_PARAMETER;
        }
 
-       Context *context = static_cast<Context *>(handle);
-       auto task = static_cast<FaceRecognitionTask *>(context->__tasks["face_recognition"]);
+       try {
+               Context *context = static_cast<Context *>(handle);
+               auto task = static_cast<FaceRecognitionTask *>(context->__tasks["face_recognition"]);
 
-       task->configure();
-       task->prepare();
+               task->configure();
+               task->prepare();
+       } catch (const BaseException& e) {
+               LOGE("%s", e.what());
+               return e.getError();
+       }
 
        LOGD("LEAVE");
 
@@ -129,7 +134,7 @@ int mv_face_recognition_register_open(mv_face_recognition_h handle, mv_source_h
                task->setInput(input);
                task->perform();
        } catch (const BaseException& e) {
-               LOGE("Fail to register new face.");
+               LOGE("%s", e.what());
                return e.getError();
        }
 
@@ -158,7 +163,7 @@ int mv_face_recognition_unregister_open(mv_face_recognition_h handle, const char
                task->setInput(input);
                task->perform();
        } catch (const BaseException& e) {
-               LOGE("Fail to unregister a given label.");
+               LOGE("%s", e.what());
                return e.getError();
        }
 
@@ -186,7 +191,7 @@ int mv_face_recognition_inference_open(mv_face_recognition_h handle, mv_source_h
                task->setInput(input);
                task->perform();
        } catch (const BaseException& e) {
-               LOGE("Fail to recognize a face.");
+               LOGE("%s", e.what());
                return e.getError();
        }
 
@@ -210,7 +215,7 @@ int mv_face_recognition_get_label_open(mv_face_recognition_h handle, const char
 
                *out_label = task->getOutput().label.c_str();
        } catch (const BaseException& e) {
-               LOGE("Fail to get label.");
+               LOGE("%s", e.what());
                return e.getError();
        }