From 9daa585995d1192ac43dc99100214f18177e9753 Mon Sep 17 00:00:00 2001 From: LiAn Date: Fri, 8 Apr 2022 08:33:03 +0000 Subject: [PATCH] update zh-cn/application-dev/device/sensor-guidelines.md. Signed-off-by: lian --- zh-cn/application-dev/device/sensor-guidelines.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zh-cn/application-dev/device/sensor-guidelines.md b/zh-cn/application-dev/device/sensor-guidelines.md index 8d5ea44d2a..083157886c 100644 --- a/zh-cn/application-dev/device/sensor-guidelines.md +++ b/zh-cn/application-dev/device/sensor-guidelines.md @@ -111,3 +111,15 @@ 以SensorType为SENSOR_TYPE_ID_ACCELEROMETER为例展示运行结果,获取数据成功日志如下图所示: ![zh-cn_image_0000001241733907](figures/zh-cn_image_0000001241733907.png) + + 若接口调用不成功,建议使用try/catch语句捕获代码中可能出现的错误信息。例如: + + ``` + try { + sensor.once(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function(data) { + console.info("Data obtained successfully. data=" + data);//获取数据成功,打印对应传感器的数据 + }); + } catch (error) { + console.error(error); + } + ``` -- GitLab