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