From ad2e4d4fd0d94f93db447c922aa3ff3d127ed70b Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 23 May 2024 14:19:38 +0900 Subject: [PATCH] Add try-catch for sensord_start function 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 --- src/sensor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sensor.cpp b/src/sensor.cpp index 0cfb1b4..7780491 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -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; -- 2.7.4