Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
57 lines (36 loc) · 1.46 KB
/
Copy pathindex.md
File metadata and controls
57 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "Sensor: error event"
short-title: error
slug: Web/API/Sensor/error_event
page-type: web-api-event
browser-compat: api.Sensor.error_event
---
{{securecontext_header}}{{APIRef("Sensor API")}}
The **`error`** event is fired when an exception occurs on a sensor.
The {{domxref('Sensor')}} interface is a base class, `onerror` and the `error` event may only be used
on one of the [derived classes](/en-US/docs/Web/API/Sensor#interfaces_based_on_sensor).
After this event has occurred, the {{domxref('Sensor')}} object becomes idle. If the sensor was reading values, it will stop until it restarts.
## Syntax
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
```js-nolint
addEventListener("error", (event) => { })
onerror = (event) => { }
```
## Event type
A {{domxref("SensorErrorEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("SensorErrorEvent")}}
## Examples
### Log accelerometer exceptions
This example adds an event listener to log errors that occurred on an {{domxref("Accelerometer")}}.
```js
const acl = new Accelerometer({ frequency: 60 });
acl.addEventListener("error", (error) => console.log(`Error: ${error.name}`));
acl.start();
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Sensor {{domxref('Sensor.activate_event', 'activate')}} event
- Sensor {{domxref('Sensor.reading_event', 'reading')}} event