js-apis-inner-application-errorObserver.md 950 字节
Newer Older
1 2
# ErrorObserver

3
The **ErrorObserver** module defines an observer to listen for application errors. It can be used as an input parameter in [registerErrorObserver](js-apis-application-errorManager.md#errormanagerregistererrorobserver) to listen for errors that occur in the current application.
4

5
## onUnhandledException
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

onUnhandledException(errMsg: string): void;

Called when an unhandled exception occurs in the JS runtime.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errMsg | string | No| Message and error stack trace about the exception.|

**Example**

```ts
22
import errorManager from '@ohos.application.errorManager';
23 24 25

let observer = {
    onUnhandledException(errorMsg) {
26
        console.log('onUnhandledException, errorMsg: ' + JSON.stringify(errorMsg));
27
    }
28 29
};
errorManager.registerErrorObserver(observer);
30
```