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> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import errorManager from '@ohos.app.ability.errorManager'; 13``` 14 15## ErrorObserver.onUnhandledException 16 17onUnhandledException(errMsg: string): void; 18 19Called when an unhandled exception occurs in the JS runtime. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23**Parameters** 24 25| Name| Type| Mandatory| Description| 26| -------- | -------- | -------- | -------- | 27| errMsg | string | No| Message and error stack trace about the exception.| 28 29**Example** 30 31```ts 32import errorManager from '@ohos.app.ability.errorManager'; 33 34let observer = { 35 onUnhandledException(errorMsg) { 36 console.error('onUnhandledException, errorMsg: ', errorMsg); 37 } 38}; 39 40try { 41 errorManager.on('error', observer); 42} catch (error) { 43 console.error('registerErrorObserver failed, error.code: ${error.code}, error.message: ${error.message}'); 44} 45``` 46``` 47