Add try-catch for sensord_start function 49/311649/1 accepted/tizen_unified_dev accepted/tizen/unified/20240603.160938 accepted/tizen/unified/dev/20240620.004445 accepted/tizen/unified/toolchain/20240624.121643 accepted/tizen/unified/x/20240605.012803 accepted/tizen/unified/x/asan/20240625.092828
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 23 May 2024 05:19:38 +0000 (14:19 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 23 May 2024 05:19:38 +0000 (14:19 +0900)
The capi function sensor_listener_start may throw std::invalid_argument
but this function can be used in C(which cannot handle thrown
exceptions) so a try-catch statement is added to handle this exception.

Change-Id: Ie5fd0d751e86697e08ea55f23c764bf224791322
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/sensor.cpp

index 0cfb1b4..7780491 100644 (file)
@@ -479,8 +479,13 @@ int sensor_listener_start(sensor_listener_h listener)
        id = listener->id;
        pause = listener->pause;
 
-       if (!sensord_start(id, 0))
+       try {
+               if (!sensord_start(id, 0))
+                       return SENSOR_ERROR_OPERATION_FAILED;
+       } catch (std::invalid_argument &e) {
+               _E("sensord_start failed: %s", e.what());
                return SENSOR_ERROR_OPERATION_FAILED;
+       }
 
        if (sensord_listener_set_attribute_int(id, SENSOR_ATTRIBUTE_PAUSE_POLICY, pause) < 0)
                return SENSOR_ERROR_OPERATION_FAILED;