• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ErrorObserver
2
3The **ErrorObserver** module defines an observer to listen for application errors. It can be used as an input parameter in [errorManager.on](js-apis-app-ability-errorManager.md#errormanageron) to listen for errors that occur in the current application.
4
5## onUnhandledException
6
7onUnhandledException(errMsg: string): void;
8
9Called when an unhandled exception occurs in the JS runtime.
10
11**System capability**: SystemCapability.Ability.AbilityRuntime.Core
12
13**Parameters**
14
15| Name| Type| Mandatory| Description|
16| -------- | -------- | -------- | -------- |
17| errMsg | string | No| Message and error stack trace about the exception.|
18
19**Example**
20
21```ts
22import errorManager from '@ohos.app.ability.errorManager';
23
24let observer = {
25    onUnhandledException(errorMsg) {
26        console.log('onUnhandledException, errorMsg: ' + JSON.stringify(errorMsg));
27    }
28};
29errorManager.on('error',observer);
30```
31