From 458124617bbf65592ae0a1872b0bcab5af8b7d2e Mon Sep 17 00:00:00 2001 From: csw Date: Mon, 23 Jun 2025 22:53:44 +0800 Subject: [PATCH] =?UTF-8?q?ani=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: csw --- api/@ohos.app.ability.errorManager.d.ts | 155 +++++++++++++++++++++++- api/application/ErrorObserver.d.ts | 29 +++++ api/application/LoopObserver.d.ts | 20 +++ 3 files changed, 199 insertions(+), 5 deletions(-) diff --git a/api/@ohos.app.ability.errorManager.d.ts b/api/@ohos.app.ability.errorManager.d.ts index 0cfab9798a..fba090a7e0 100644 --- a/api/@ohos.app.ability.errorManager.d.ts +++ b/api/@ohos.app.ability.errorManager.d.ts @@ -37,6 +37,16 @@ import { LoopObserver as _LoopObserver } from './application/LoopObserver'; * @atomicservice * @since 11 */ +/** + * This module provides the function of error manager. + * + * @namespace errorManager + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ declare namespace errorManager { /** * Register error observer. @@ -46,7 +56,7 @@ declare namespace errorManager { * @returns { number } Returns the number code of the observer. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. - * @throws { BusinessError } 16000003 - Id does not exist. + * @throws { BusinessError } 16000003 - The specified ID does not exist. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @since 9 */ @@ -63,6 +73,21 @@ declare namespace errorManager { * @atomicservice * @since 11 */ + /** + * Register error observer. + * + * @param { 'error' } type - error. + * @param { ErrorObserver } observer - The error observer. + * @returns { number } Returns the number code of the observer. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + * 2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 16000003 - The specified ID does not exist. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ function on(type: 'error', observer: ErrorObserver): number; /** @@ -73,7 +98,7 @@ declare namespace errorManager { * @param { AsyncCallback } callback - The callback of off. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. - * @throws { BusinessError } 16000003 - Id does not exist. + * @throws { BusinessError } 16000003 - The specified ID does not exist. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @since 9 */ @@ -90,6 +115,21 @@ declare namespace errorManager { * @atomicservice * @since 11 */ + /** + * Unregister error observer. + * + * @param { 'error' } type - error. + * @param { number } observerId - Indicates the number code of the observer. + * @param { AsyncCallback } callback - The callback of off. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + * 2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 16000003 - The specified ID does not exist. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ function off(type: 'error', observerId: number, callback: AsyncCallback): void; /** @@ -100,7 +140,7 @@ declare namespace errorManager { * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. - * @throws { BusinessError } 16000003 - Id does not exist. + * @throws { BusinessError } 16000003 - The specified ID does not exist. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @since 9 */ @@ -117,6 +157,21 @@ declare namespace errorManager { * @atomicservice * @since 11 */ + /** + * Unregister error observer. + * + * @param { 'error' } type - error. + * @param { number } observerId - Indicates the number code of the observer. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + * 2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 16000003 - The specified ID does not exist. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ function off(type: 'error', observerId: number): Promise; /** @@ -272,6 +327,22 @@ declare namespace errorManager { * @atomicservice * @since 12 */ + /** + * Register loop observer. This function can only by called from main thread, + * and if call this function multiple times, the last + * modification will overwrite the previous one. + * + * @param { 'loopObserver' } type - loopObserver. + * @param { number } timeout - Indicates timeout(ms) value of loop observer. + * @param { LoopObserver } observer - The loop observer. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + * 2. Incorrect parameter types; 3. Parameter verification failed. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ function on(type: 'loopObserver', timeout: number, observer: LoopObserver): void; /** @@ -285,6 +356,19 @@ declare namespace errorManager { * @atomicservice * @since 12 */ + /** + * Unregister loop observer. This function can only by called from main thread. + * + * @param { 'loopObserver' } type - loopObserver. + * @param { LoopObserver } observer - The loop observer. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + * 2. Incorrect parameter types; 3. Parameter verification failed. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ function off(type: 'loopObserver', observer?: LoopObserver): void; /** @@ -294,11 +378,25 @@ declare namespace errorManager { * @param { UnhandledRejectionObserver } observer - The unhandled rejection observer. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. - * @throws { BusinessError } 16200001 - If the caller is invalid. + * @throws { BusinessError } 16200001 - The caller has been released. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @atomicservice * @since 12 */ + /** + * Register unhandled rejection observer. + * + * @param { 'unhandledRejection' } type - 'unhandledRejection'. + * @param { UnhandledRejectionObserver } observer - The unhandled rejection observer. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + * 2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 16200001 - The caller has been released. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ function on(type: 'unhandledRejection', observer: UnhandledRejectionObserver): void; /** @@ -308,12 +406,27 @@ declare namespace errorManager { * @param { UnhandledRejectionObserver } [observer] - the registered observer * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; * 2. Incorrect parameter types; 3. Parameter verification failed. - * @throws { BusinessError } 16200001 - If the caller is invalid. + * @throws { BusinessError } 16200001 - The caller has been released. * @throws { BusinessError } 16300004 - If the observer does not exist * @syscap SystemCapability.Ability.AbilityRuntime.Core * @atomicservice * @since 12 */ + /** + * Unregister unhandled rejection observer. + * + * @param { 'unhandledRejection' } type - error. + * @param { UnhandledRejectionObserver } [observer] - the registered observer + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + * 2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 16200001 - The caller has been released. + * @throws { BusinessError } 16300004 - If the observer does not exist + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ function off(type: 'unhandledRejection', observer?: UnhandledRejectionObserver): void; /** @@ -361,6 +474,16 @@ declare namespace errorManager { * @atomicservice * @since 11 */ + /** + * The observer will be called by system when an error occurs. + * + * @typedef { _ErrorObserver.default } + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ export type ErrorObserver = _ErrorObserver.default; /** * The observer will be called when application main thread execute timeout. @@ -370,6 +493,16 @@ declare namespace errorManager { * @atomicservice * @since 12 */ + /** + * The observer will be called when application main thread execute timeout. + * + * @typedef { _LoopObserver } + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ export type LoopObserver = _LoopObserver; /** * The observer will be called by system when an unhandled rejection occurs. @@ -381,6 +514,18 @@ declare namespace errorManager { * @atomicservice * @since 12 */ + /** + * The observer will be called by system when an unhandled rejection occurs. + * + * @typedef { function } + * { Error | any } reason - the reason of the rejection, typically of Error type + * { Promise } promise - the promise that is rejected + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ export type UnhandledRejectionObserver = (reason: Error | any, promise: Promise) => void; /** * The observer will be called by system when freeze happens. diff --git a/api/application/ErrorObserver.d.ts b/api/application/ErrorObserver.d.ts index acc0b8c036..24ee69262e 100644 --- a/api/application/ErrorObserver.d.ts +++ b/api/application/ErrorObserver.d.ts @@ -31,6 +31,15 @@ * @atomicservice * @since 11 */ +/** + * The observer will be called by system when an error occurs. + * + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ export default class ErrorObserver { /** * Will be called when the js runtime throws an exception which doesn't caught by user. @@ -47,6 +56,16 @@ export default class ErrorObserver { * @atomicservice * @since 11 */ + /** + * Will be called when the js runtime throws an exception which doesn't caught by user. + * + * @param { string } errMsg - the message and error stacktrace about the exception. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ onUnhandledException(errMsg: string): void; /** @@ -64,5 +83,15 @@ export default class ErrorObserver { * @atomicservice * @since 11 */ + /** + * Will be called when the js runtime throws an exception which doesn't caught by user. + * + * @param { Error } errObject - the error object about the exception. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ onException?(errObject: Error): void; } diff --git a/api/application/LoopObserver.d.ts b/api/application/LoopObserver.d.ts index 24f582f9d1..9e31616201 100644 --- a/api/application/LoopObserver.d.ts +++ b/api/application/LoopObserver.d.ts @@ -26,6 +26,16 @@ * @atomicservice * @since 12 */ +/** + * The observer will be called by system when application main thread loop + * execute timeout + * @interface LoopObserver + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ export interface LoopObserver { /** * Will be called when the application main thread loop execute timeout. @@ -35,5 +45,15 @@ export interface LoopObserver { * @atomicservice * @since 12 */ + /** + * Will be called when the application main thread loop execute timeout. + * + * @param { number } timeout - the actual executing time of loop event. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @crossplatform + * @atomicservice + * @since arkts {'1.1':'19', '1.2':'20'} + * @arkts 1.1&1.2 + */ onLoopTimeOut?(timeout: number): void; } -- Gitee