1# @ohos.app.ability.errorManager (Error Observation Management) 2 3The ErrorManager module provides APIs for registering and unregistering error observers. 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```ts 11import { errorManager } from '@kit.AbilityKit'; 12``` 13 14## errorManager.on('error') 15 16> **NOTE** 17> 18> The **errormanager.on** API is registered only in the main thread. Currently, exceptions in child threads (such as TaskPool threads) cannot be captured. 19> 20> The application does not exit during the use of **errormanager.on**. You are advised to add the synchronous exit operation after the callback function is executed. 21 22on(type: 'error', observer: ErrorObserver): number 23 24Registers an error observer. After the registration, JS crashes generated by the application can be captured. When the application breaks down, the process does not exit. 25 26**Atomic service API**: This API can be used in atomic services since API version 11. 27 28**System capability**: SystemCapability.Ability.AbilityRuntime.Core 29 30**Parameters** 31 32| Name| Type| Mandatory| Description| 33| -------- | -------- | -------- | -------- | 34| type | string | Yes| Event type. It is fixed at **'error'**.| 35| observer | [ErrorObserver](js-apis-inner-application-errorObserver.md) | Yes| Digital code of the observer.| 36 37**Return value** 38 39 | Type| Description| 40 | -------- | -------- | 41 | number | Index of the observer.| 42 43**Error codes** 44 45For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 46 47| ID| Error Message| 48| ------- | -------- | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 50| 16000003 | The specified ID does not exist. | 51 52**Example** 53 54```ts 55import { errorManager } from '@kit.AbilityKit'; 56import { BusinessError } from '@kit.BasicServicesKit'; 57 58let observer: errorManager.ErrorObserver = { 59 onUnhandledException(errorMsg) { 60 console.info('onUnhandledException, errorMsg: ', errorMsg); 61 }, 62 onException(errorObj) { 63 console.info('onException, name: ', errorObj.name); 64 console.info('onException, message: ', errorObj.message); 65 if (typeof(errorObj.stack) === 'string') { 66 console.info('onException, stack: ', errorObj.stack); 67 } 68 } 69}; 70let observerId = -1; 71 72try { 73 observerId = errorManager.on('error', observer); 74} catch (paramError) { 75 let code = (paramError as BusinessError).code; 76 let message = (paramError as BusinessError).message; 77 console.error(`error: ${code}, ${message}`); 78} 79``` 80 81## errorManager.on('globalErrorOccurred')<sup>18+</sup> 82 83on(type: 'globalErrorOccurred', observer: GlobalObserver): void 84 85Registers a global error observer with any thread in the process to capture exceptions in other child threads (such as TaskPool threads). When the application breaks down, the process does not exit. You are advised to add the synchronous exit operation after the callback function is executed. 86 87**Atomic service API**: This API can be used in atomic services since API version 18. 88 89**System capability**: SystemCapability.Ability.AbilityRuntime.Core 90 91**Parameters** 92 93| Name| Type| Mandatory| Description| 94| -------- | -------- | -------- | -------- | 95| type | string | Yes| Event type. It is fixed at **'globalErrorOccurred'**.| 96| observer | [GlobalObserver](#globalobserver18) | Yes| Customized callback function for exception handling.| 97 98**Error codes** 99 100For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 101 102| ID| Error Message| 103| ------- | -------- | 104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 105| 16200001 | The caller has been released. | 106 107**Example** 108 109```ts 110import { errorManager } from '@kit.AbilityKit'; 111import { BusinessError } from '@kit.BasicServicesKit'; 112 113function errorFunc(observer: errorManager.GlobalError) { 114 console.info("result name :" + observer.name); 115 console.info("result message :" + observer.message); 116 console.info("result stack :" + observer.stack); 117 console.info("result instanceName :" + observer.instanceName); 118 console.info("result instanceType :" + observer.instanceType); 119} 120 121try { 122 errorManager.on('globalErrorOccurred', errorFunc); 123} catch (paramError) { 124 let code = (paramError as BusinessError).code; 125 let message = (paramError as BusinessError).message; 126 console.error(`error: ${code}, ${message}`); 127} 128``` 129 130## errorManager.off('globalErrorOccurred')<sup>18+</sup> 131 132off(type: 'globalErrorOccurred', observer?: GlobalObserver): void 133 134Unregisters a global error observer. After the deregistration, global listening cannot be implemented. 135 136If the observer passed in is not in the observer queue registered via the **on** API, error code 16300004 is thrown. Therefore, you are advised to handle this using **try-catch** logic. 137 138**Atomic service API**: This API can be used in atomic services since API version 18. 139 140**System capability**: SystemCapability.Ability.AbilityRuntime.Core 141 142**Parameters** 143 144| Name| Type| Mandatory| Description| 145| -------- | -------- | -------- | -------- | 146| type | string | Yes| Event type. It is fixed at **'globalErrorOccurred'**.| 147| observer | [GlobalObserver](#globalobserver18) | No| Observer registered by the **on** API. You are advised to use this parameter. If omitted, all observers registered with the same environment through **on** are unregistered by default. Otherwise, the specified observer is unregistered. | 148 149**Error codes** 150 151For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 152 153| ID| Error Message| 154| ------- | -------- | 155| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 156| 16200001 | The caller has been released. | 157| 16300004 | The observer does not exist. | 158 159**Example** 160 161```ts 162import { errorManager } from '@kit.AbilityKit'; 163import { BusinessError } from '@kit.BasicServicesKit'; 164 165function errorFunc(observer: errorManager.GlobalError) { 166 console.info("result name :" + observer.name); 167 console.info("result message :" + observer.message); 168 console.info("result stack :" + observer.stack); 169 console.info("result instanceName :" + observer.instanceName); 170 console.info("result instanceType :" + observer.instanceType); 171} 172 173try { 174 errorManager.off('globalErrorOccurred', errorFunc) 175} catch (paramError) { 176 let code = (paramError as BusinessError).code; 177 let message = (paramError as BusinessError).message; 178 console.error(`error: ${code}, ${message}`); 179} 180``` 181 182## errorManager.off('error') 183 184off(type: 'error', observerId: number, callback: AsyncCallback\<void>): void 185 186Unregisters an error observer. This API uses an asynchronous callback to return the result. 187 188**Atomic service API**: This API can be used in atomic services since API version 11. 189 190**System capability**: SystemCapability.Ability.AbilityRuntime.Core 191 192**Parameters** 193 194| Name| Type| Mandatory| Description| 195| -------- | -------- | -------- | -------- | 196| type | string | Yes| Event type. It is fixed at **'error'**.| 197| observerId | number | Yes| Index of the observer returned by **on()**.| 198| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| 199 200**Error codes** 201 202For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 203 204| ID| Error Message| 205| ------- | -------- | 206| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 207| 16000003 | The specified ID does not exist. | 208 209**Example** 210 211```ts 212import { errorManager } from '@kit.AbilityKit'; 213import { BusinessError } from '@kit.BasicServicesKit'; 214 215let observerId = 100; 216 217function unregisterErrorObserverCallback(err: BusinessError) { 218 if (err) { 219 console.error('------------ unregisterErrorObserverCallback ------------', err); 220 } 221} 222 223try { 224 errorManager.off('error', observerId, unregisterErrorObserverCallback); 225} catch (paramError) { 226 let code = (paramError as BusinessError).code; 227 let message = (paramError as BusinessError).message; 228 console.error(`error: ${code}, ${message}`); 229} 230``` 231 232## errorManager.off('error') 233 234off(type: 'error', observerId: number): Promise\<void> 235 236Unregisters an error observer. This API uses a promise to return the result. 237 238**Atomic service API**: This API can be used in atomic services since API version 11. 239 240**System capability**: SystemCapability.Ability.AbilityRuntime.Core 241 242**Parameters** 243 244| Name| Type| Mandatory| Description| 245| -------- | -------- | -------- | -------- | 246| type | string | Yes| Event type. It is fixed at **'error'**.| 247| observerId | number | Yes| Index of the observer returned by **on()**.| 248 249**Return value** 250 251| Type| Description| 252| -------- | -------- | 253| Promise\<void> | Promise that returns no value.| 254 255**Error codes** 256 257For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 258 259| ID| Error Message| 260| ------- | -------- | 261| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 262| 16000003 | The specified ID does not exist. | 263 264**Example** 265 266```ts 267import { errorManager } from '@kit.AbilityKit'; 268import { BusinessError } from '@kit.BasicServicesKit'; 269 270let observerId = 100; 271 272try { 273 errorManager.off('error', observerId) 274 .then((data) => { 275 console.info('----------- unregisterErrorObserver success ----------', data); 276 }) 277 .catch((err: BusinessError) => { 278 console.error('----------- unregisterErrorObserver fail ----------', err); 279 }); 280} catch (paramError) { 281 let code = (paramError as BusinessError).code; 282 let message = (paramError as BusinessError).message; 283 console.error(`error: ${code}, ${message}`); 284} 285``` 286 287## errorManager.on('loopObserver')<sup>12+</sup> 288 289on(type: 'loopObserver', timeout: number, observer: LoopObserver): void 290 291Registers an observer for the message processing duration of the main thread. After the registration, the execution time of a message processed by the main thread of the application can be captured. 292 293**Atomic service API**: This API can be used in atomic services since API version 12. 294 295**System capability**: SystemCapability.Ability.AbilityRuntime.Core 296 297**Parameters** 298 299| Name| Type| Mandatory| Description| 300| -------- | -------- | -------- | -------- | 301| type | string | Yes| Event type. It is fixed at **'loopObserver'**, indicating an observer for the message processing duration of the main thread.| 302| timeout | number | Yes| Event execution threshold, in milliseconds. The value must be greater than **0**.| 303| observer | [LoopObserver](js-apis-inner-application-loopObserver.md) | Yes| Observer to register.| 304 305**Error codes** 306 307For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 308 309| ID| Error Message| 310| ------- | -------- | 311| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 312 313**Example** 314 315```ts 316import { errorManager } from '@kit.AbilityKit'; 317 318let observer: errorManager.LoopObserver = { 319 onLoopTimeOut(timeout: number) { 320 console.info('Duration timeout: ' + timeout); 321 } 322}; 323 324errorManager.on("loopObserver", 1, observer); 325``` 326 327## errorManager.on('globalUnhandledRejectionDetected')<sup>18+</sup> 328 329on(type: 'globalUnhandledRejectionDetected', observer: GlobalObserver): void 330 331Registers a rejected promise observer with any thread in the process. After the registration, a rejected promise that is not captured in the current thread of the application can be captured. 332 333**Atomic service API**: This API can be used in atomic services since API version 18. 334 335**System capability**: SystemCapability.Ability.AbilityRuntime.Core 336 337**Parameters** 338 339| Name | Type | Mandatory| Description | 340|-----------------------|-------------------------------------------------------------| -------- |------------------------------------------| 341| type | string | Yes| Event type. It is fixed at **'globalUnhandledRejectionDetected'**, indicating an observer for the promise rejection.| 342| observer | [GlobalObserver](#globalobserver18) | Yes| Observer to register. | 343 344**Error codes** 345 346For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 347 348| ID| Error Message| 349| ------- | -------- | 350| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 351| 16200001 | The caller has been released. | 352 353**Example** 354 355```ts 356import { errorManager } from '@kit.AbilityKit'; 357 358function promiseFunc(observer: errorManager.GlobalError) { 359 console.info("result name :" + observer.name); 360 console.info("result message :" + observer.message); 361 console.info("result stack :" + observer.stack); 362 console.info("result instanceName :" + observer.instanceName); 363 console.info("result instanceType :" + observer.instanceType); 364} 365 366errorManager.on("globalUnhandledRejectionDetected", promiseFunc); 367// You are advised to use async to throw a promise exception. 368async function throwError() { 369 throw new Error("uncaught error"); 370} 371 372let promise1 = new Promise<void>(() => {}).then(() => { 373 throwError(); 374}); 375``` 376 377## errorManager.on('unhandledRejection')<sup>12+</sup> 378 379on(type: 'unhandledRejection', observer: UnhandledRejectionObserver): void 380 381Registers an observer for the promise rejection. After the registration, a rejected promise that is not captured in the current thread of the application can be captured. 382 383**Atomic service API**: This API can be used in atomic services since API version 12. 384 385**System capability**: SystemCapability.Ability.AbilityRuntime.Core 386 387**Parameters** 388 389| Name | Type | Mandatory| Description | 390|-----------------------|-------------------------------------------------------------| -------- |------------------------------------------| 391| type | string | Yes| Event type. It is fixed at **'unhandledRejection'**, indicating an observer for the promise rejection.| 392| observer | [UnhandledRejectionObserver](#unhandledrejectionobserver12) | Yes| Observer to register. | 393 394**Error codes** 395 396For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 397 398| ID| Error Message| 399| ------- | -------- | 400| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 401| 16200001 | The caller has been released. | 402 403**Example** 404 405```ts 406import { errorManager } from '@kit.AbilityKit'; 407 408let observer: errorManager.UnhandledRejectionObserver = (reason: Error, promise: Promise<void>) => { 409 if (promise === promise1) { 410 console.info("promise1 is rejected"); 411 } 412 console.info("reason.name: ", reason.name); 413 console.info("reason.message: ", reason.message); 414 if (reason.stack) { 415 console.info("reason.stack: ", reason.stack); 416 } 417}; 418 419errorManager.on("unhandledRejection", observer); 420 421let promise1 = new Promise<void>(() => {}).then(() => { 422 throw new Error("uncaught error"); 423}); 424``` 425## errorManager.on('freeze')<sup>18+</sup> 426 427on(type: 'freeze', observer: FreezeObserver): void 428 429Registers an observer for the main thread freeze event of the application. This API can be called only in the main thread. A new observer will overwrite the previous one. 430 431> **NOTE** 432> 433> If the callback function runs for more than 1 second, the [AppRecovery](./js-apis-app-ability-appRecovery.md) feature may not work. The execution duration can be calculated by parsing the time difference between **begin** and **Freeze callback execution completed** in HiLogs. If the execution duration exceeds 1 second, you can optimize the callback logic by using methods such as asynchronous processing, reducing operations that block other tasks, and optimizing the data structures to reduce the execution duration. 434> 435 436**Atomic service API**: This API can be used in atomic services since API version 18. 437 438**System capability**: SystemCapability.Ability.AbilityRuntime.Core 439 440**Parameters** 441 442| Name| Type| Mandatory| Description| 443| -------- | -------- | -------- | -------- | 444| type | string | Yes| Event type. It is fixed at **'freeze'**, indicating an observer for the freeze event of the main thread.| 445| observer | [FreezeObserver](#freezeobserver18) | Yes| Observer to register.| 446 447**Error codes** 448 449For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 450 451| ID| Error Message| 452| ------- | -------- | 453| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 454 455**Example** 456 457```ts 458import { errorManager } from '@kit.AbilityKit'; 459 460function freezeCallback() { 461 console.info("freezecallback"); 462} 463errorManager.on("freeze", freezeCallback); 464``` 465 466## errorManager.off('loopObserver')<sup>12+</sup> 467 468off(type: 'loopObserver', observer?: LoopObserver): void 469 470Unregisters an observer for the message processing duration of the main thread. 471 472**Atomic service API**: This API can be used in atomic services since API version 12. 473 474**System capability**: SystemCapability.Ability.AbilityRuntime.Core 475 476**Parameters** 477 478| Name| Type| Mandatory| Description| 479| -------- | -------- | -------- | -------- | 480| type | string | Yes| Event type. It is fixed at **'loopObserver'**, indicating an observer for the message processing duration of the main thread.| 481| observer | [LoopObserver](js-apis-inner-application-loopObserver.md) | No| Observer to unregister.| 482 483**Error codes** 484 485For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 486 487| ID| Error Message| 488| ------- | -------- | 489| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 490 491**Example** 492 493```ts 494import { errorManager } from '@kit.AbilityKit'; 495 496errorManager.off("loopObserver"); 497``` 498 499## errorManager.off('globalUnhandledRejectionDetected')<sup>18+</sup> 500 501off(type: 'globalUnhandledRejectionDetected', observer?: GlobalObserver): void 502 503Unregisters a rejected promise observer. After the deregistration, promise exceptions in the process cannot be listened for. 504 505If the observer passed in is not in the observer queue registered via the **on** API, error code 16300004 is thrown. Therefore, you are advised to handle this using **try-catch** logic. 506 507**Atomic service API**: This API can be used in atomic services since API version 18. 508 509**System capability**: SystemCapability.Ability.AbilityRuntime.Core 510 511**Parameters** 512 513| Name | Type | Mandatory| Description | 514|-----------------------|---------------------------------|----|----------------------------------------------| 515| type | string | Yes | Event type. It is fixed at **'globalUnhandledRejectionDetected'**, indicating an observer for the promise rejection.| 516| observer | [GlobalObserver](#globalobserver18) | No | Observer registered by the **on** API. You are advised to use this parameter. If omitted, all observers registered with the same environment through **on** are unregistered by default. Otherwise, the specified observer is unregistered.| 517 518**Error codes** 519 520For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 521 522| ID| Error Message| 523| ------- | -------- | 524| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 525| 16200001 | The caller has been released. | 526| 16300004 | The observer does not exist. | 527 528**Example** 529 530```ts 531import { errorManager } from '@kit.AbilityKit'; 532 533function promiseFunc(observer: errorManager.GlobalError) { 534 console.info("result name :" + observer.name); 535 console.info("result message :" + observer.message); 536 console.info("result stack :" + observer.stack); 537 console.info("result instanceName :" + observer.instanceName); 538 console.info("result instanceType :" + observer.instanceType); 539} 540 541errorManager.on("globalUnhandledRejectionDetected", promiseFunc); 542 543async function throwError() { 544 throw new Error("uncaught error"); 545} 546 547let promise1 = new Promise<void>(() => {}).then(() => { 548 throwError(); 549}); 550 551errorManager.off("globalUnhandledRejectionDetected", promiseFunc); 552``` 553 554## errorManager.off('unhandledRejection')<sup>12+</sup> 555 556off(type: 'unhandledRejection', observer?: UnhandledRejectionObserver): void 557 558Unregisters an observer for the promise rejection. 559 560**Atomic service API**: This API can be used in atomic services since API version 12. 561 562**System capability**: SystemCapability.Ability.AbilityRuntime.Core 563 564**Parameters** 565 566| Name | Type | Mandatory| Description | 567|-----------------------|---------------------------------|----|----------------------------------------------| 568| type | string | Yes | Event type. It is fixed at **'unhandledRejection'**, indicating an observer for the promise rejection.| 569| observer | [UnhandledRejectionObserver](#unhandledrejectionobserver12) | No | Observer to unregister. You are advised to use this parameter. If omitted, all observers registered with the same environment through **on** are unregistered by default. Otherwise, the specified observer is unregistered. | 570 571**Error codes** 572 573For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 574 575| ID| Error Message| 576| ------- | -------- | 577| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 578| 16200001 | The caller has been released. | 579| 16300004 | The observer does not exist. | 580 581**Example** 582 583```ts 584import { errorManager } from '@kit.AbilityKit'; 585 586let observer: errorManager.UnhandledRejectionObserver = (reason: Error, promise: Promise<void>) => { 587 if (promise === promise1) { 588 console.info("promise1 is rejected"); 589 } 590 console.info("reason.name: ", reason.name); 591 console.info("reason.message: ", reason.message); 592 if (reason.stack) { 593 console.info("reason.stack: ", reason.stack); 594 } 595}; 596 597errorManager.on("unhandledRejection", observer); 598 599let promise1 = new Promise<void>(() => {}).then(() => { 600 throw new Error("uncaught error") 601}) 602 603errorManager.off("unhandledRejection"); 604``` 605Or: 606```ts 607import { errorManager } from '@kit.AbilityKit'; 608 609let observer: errorManager.UnhandledRejectionObserver = (reason: Error, promise: Promise<void>) => { 610 if (promise === promise1) { 611 console.info("promise1 is rejected"); 612 } 613 console.info("reason.name: ", reason.name); 614 console.info("reason.message: ", reason.message); 615 if (reason.stack) { 616 console.info("reason.stack: ", reason.stack); 617 } 618}; 619 620errorManager.on("unhandledRejection", observer); 621 622let promise1 = new Promise<void>(() => {}).then(() => { 623 throw new Error("uncaught error") 624}) 625 626errorManager.off("unhandledRejection", observer); 627``` 628 629## errorManager.off('freeze')<sup>18+</sup> 630 631off(type: 'freeze', observer?: FreezeObserver): void 632 633Unregisters an observer for the main thread freeze event of the application. This API can be called only in the main thread. 634 635If the observer passed in does not match the observer registered via the **on** API, error code 16300004 is thrown. Therefore, you are advised to handle this using **try-catch** logic. 636 637**Atomic service API**: This API can be used in atomic services since API version 18. 638 639**System capability**: SystemCapability.Ability.AbilityRuntime.Core 640 641**Parameters** 642 643| Name| Type| Mandatory| Description| 644| -------- | -------- | -------- | -------- | 645| type | string | Yes| Event type. It is fixed at **'freeze'**, indicating an observer for the freeze event of the main thread.| 646| observer | [FreezeObserver](#freezeobserver18) | No| Observer to unregister. You are advised to use this parameter. If omitted, all observers registered with the same environment through **on** are unregistered by default. Otherwise, the specified observer is unregistered.| 647 648**Error codes** 649 650For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 651 652| ID| Error Message| 653| ------- | -------- | 654| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 655| 16300004 | The observer does not exist. | 656 657**Example** 658 659```ts 660import { errorManager } from '@kit.AbilityKit'; 661 662function freezeCallback() { 663 console.info("freezecallback"); 664} 665errorManager.on("freeze", freezeCallback); 666errorManager.off("freeze", freezeCallback); 667``` 668 669## ErrorObserver 670 671type ErrorObserver = _ErrorObserver.default 672 673Defines the ErrorObserver module. 674 675**Atomic service API**: This API can be used in atomic services since API version 11. 676 677**System capability**: SystemCapability.Ability.AbilityRuntime.Core 678 679| Type| Description| 680| --- | --- | 681| [_ErrorObserver.default](js-apis-inner-application-errorObserver.md) | ErrorObserver module.| 682 683## LoopObserver<sup>12+</sup> 684 685type LoopObserver = _LoopObserver 686 687Defines the LoopObserver module. 688 689**Atomic service API**: This API can be used in atomic services since API version 12. 690 691**System capability**: SystemCapability.Ability.AbilityRuntime.Core 692 693| Type| Description| 694| --- | --- | 695| [_LoopObserver](js-apis-inner-application-loopObserver.md) | LoopObserver module.| 696 697## UnhandledRejectionObserver<sup>12+</sup> 698 699type UnhandledRejectionObserver = (reason: Error | any, promise: Promise\<any>) => void 700 701Defines an observer to capture the cause of a rejected promise. 702 703**Atomic service API**: This API can be used in atomic services since API version 12. 704 705**System capability**: SystemCapability.Ability.AbilityRuntime.Core 706 707**Parameters** 708 709| Name | Type | Mandatory| Description| 710|--------|---------------|---| -------- | 711| reason | Error \| any | Yes| Generally, the value is of the **Error** type, indicating the reason for rejection.| 712| promise | Promise\<any> | Yes| Rejected promise.| 713 714## FreezeObserver<sup>18+</sup> 715 716type FreezeObserver = () => void 717 718Defines an observer for the main thread freeze event of the application. It is used by the application to customize freeze information. 719 720**Atomic service API**: This API can be used in atomic services since API version 18. 721 722**System capability**: SystemCapability.Ability.AbilityRuntime.Core 723 724## GlobalObserver<sup>18+</sup> 725 726type GlobalObserver = (reason: GlobalError) => void 727 728Defines an exception observer, which can be used as the input parameter of [errorManager.on('globalErrorOccurred')](#errormanageronglobalerroroccurred18) and [errorManager.on('globalUnhandledRejectionDetected')](#errormanageronglobalunhandledrejectiondetected18) to listen for event processing events of the main thread of the current application. 729 730**Atomic service API**: This API can be used in atomic services since API version 18. 731 732**System capability**: SystemCapability.Ability.AbilityRuntime.Core 733 734**Parameters** 735 736| Name | Type | Mandatory| Description| 737|--------| ------------- | ---- | --- | 738| reason | [GlobalError](#globalerror18) | Yes | Object related to the exception event name, message, error stack information, exception thread name, and exception thread type.| 739 740 741## GlobalError<sup>18+</sup> 742 743Describes the object related to the exception event name, message, error stack information, exception thread name, and exception thread type. 744 745**Atomic service API**: This API can be used in atomic services since API version 18. 746 747**System capability**: SystemCapability.Ability.AbilityRuntime.Core 748 749| Name | Type | Read Only | Optional | Description | 750| ---- | ----- | ---- | ----- | ------ | 751| instanceName | string | No| No| Name of a VM instance.| 752| instanceType | [InstanceType](#instancetype18) | No| No| Type of the VM instance.| 753 754## InstanceType<sup>18+</sup> 755 756Enumerates the VM instance types. 757 758**Atomic service API**: This API can be used in atomic services since API version 18. 759 760**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 761 762| Name | Value | Description | 763| ---- | --- | ------ | 764| MAIN | 0 | Main VM instance.| 765| WORKER | 1 | Worker VM instance.| 766| TASKPOOL | 2 | TaskPool VM instance.| 767| CUSTOM | 3 | VM instance created from the local code using [napi_create_ark_runtime](../native-lib/napi.md#napi_create_ark_runtime).| 768