46 Star 176 Fork 4.8K

OpenHarmony/interface_sdk-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
@ohos.app.ability.errorManager.d.ts 21.18 KB
一键复制 编辑 原始数据 按行查看 历史
Cyf 提交于 4天前 . API modification
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
/*
* Copyright (c) 2022-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @kit AbilityKit
*/
import { AsyncCallback } from './@ohos.base';
import * as _ErrorObserver from './application/ErrorObserver';
import { LoopObserver as _LoopObserver } from './application/LoopObserver';
/**
* This module provides the function of error manager.
*
* @namespace errorManager
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @since 9
*/
/**
* This module provides the function of error manager.
*
* @namespace errorManager
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 11
*/
/**
* This module provides the function of error manager.
*
* @namespace errorManager
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @crossplatform
* @atomicservice
* @since 19
*/
declare namespace errorManager {
/**
* 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
* @since 9
*/
/**
* 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
* @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 19
*/
function on(type: 'error', observer: ErrorObserver): number;
/**
* Unregister error observer.
*
* @param { 'error' } type - error.
* @param { number } observerId - Indicates the number code of the observer.
* @param { AsyncCallback<void> } 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
* @since 9
*/
/**
* Unregister error observer.
*
* @param { 'error' } type - error.
* @param { number } observerId - Indicates the number code of the observer.
* @param { AsyncCallback<void> } 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
* @atomicservice
* @since 11
*/
/**
* Unregister error observer.
*
* @param { 'error' } type - error.
* @param { number } observerId - Indicates the number code of the observer.
* @param { AsyncCallback<void> } 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 19
*/
function off(type: 'error', observerId: number, callback: AsyncCallback<void>): void;
/**
* Unregister error observer.
*
* @param { 'error' } type - error.
* @param { number } observerId - Indicates the number code of the observer.
* @returns { Promise<void> } 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
* @since 9
*/
/**
* Unregister error observer.
*
* @param { 'error' } type - error.
* @param { number } observerId - Indicates the number code of the observer.
* @returns { Promise<void> } 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
* @atomicservice
* @since 11
*/
/**
* Unregister error observer.
*
* @param { 'error' } type - error.
* @param { number } observerId - Indicates the number code of the observer.
* @returns { Promise<void> } 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 19
*/
function off(type: 'error', observerId: number): Promise<void>;
/**
* Register an error observer for all VM instances include worker and taskpool.
* @param { 'globalErrorOccurred'} type - globalErrorOccurred
* @param { GlobalObserver } observer - the global error 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
* @atomicservice
* @since 18
*/
function on(type: 'globalErrorOccurred', observer: GlobalObserver): void;
/**
* Register a rejection observer for all VM instances include worker and taskpool.
* @param { 'globalUnhandledRejectionDetected'} type - globalUnhandledRejectionDetected.
* @param { GlobalObserver } observer - the global error 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
* @atomicservice
* @since 18
*/
function on(type: 'globalUnhandledRejectionDetected', observer: GlobalObserver): void;
/**
* Unregister the error observer for all VM instance include worker and taskpool.
* @param { 'globalErrorOccurred'} type - globalErrorOccurred.
* @param { GlobalObserver } observer - the global error 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 - The observer does not exist.
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
function off(type: 'globalErrorOccurred', observer?: GlobalObserver): void;
/**
* Unregister the rejection observer for all VM instance include worker and taskpool.
* @param { 'globalUnhandledRejectionDetected'} type - globalUnhandledRejectionDetected.
* @param { GlobalObserver } observer - the global error 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 - The observer does not exist.
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
function off(type: 'globalUnhandledRejectionDetected', observer?: GlobalObserver): void;
/**
* The observer will be called by system when an error or unhandled rejection occurs
* from all VM instances include worker and taskpool.
* @typedef { function }
* { GlobalError } reason - the reason of the error or rejection.
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
export type GlobalObserver = (reason: GlobalError) => void;
/**
* Defines GlobalError.
*
* @extends Error
* @typedef GlobalError
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
export interface GlobalError extends Error {
/**
* Define the instance name of VM.
* @type { string } instanceName
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
instanceName: string;
/**
* Define the instance type of VM.
* @type { InstanceType } instanceType
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
instanceType: InstanceType;
}
/**
* Define the instance type of VM.
* @enum { number }
* @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
* @atomicservice
* @since 18
*/
export enum InstanceType {
/**
* Indicates it is the main VM instance.
*
* @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
* @atomicservice
* @since 18
*/
MAIN = 0,
/**
* Indicates it is the worker VM instance.
*
* @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
* @atomicservice
* @since 18
*/
WORKER = 1,
/**
* Indicates it is the taskpool VM instance.
*
* @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
* @atomicservice
* @since 18
*/
TASKPOOL = 2,
/**
* Indicates it is a VM instance created by napi_create_ark_runtime from native code by user.
*
* @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore
* @atomicservice
* @since 18
*/
CUSTOM = 3,
}
/**
* 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
* @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 19
*/
function on(type: 'loopObserver', timeout: number, observer: LoopObserver): void;
/**
* 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
* @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 19
*/
function off(type: 'loopObserver', observer?: LoopObserver): void;
/**
* 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
* @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 19
*/
function on(type: 'unhandledRejection', observer: UnhandledRejectionObserver): void;
/**
* 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 - 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 - The observer does not exist.
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @crossplatform
* @atomicservice
* @since 19
*/
function off(type: 'unhandledRejection', observer?: UnhandledRejectionObserver): void;
/**
* Register an observer for freeze event.
* This function can only be called from main thread.
* Please note that each process only supports registering one observer.
* If you register multiple times, the later one will overwrite the previous one.
*
* @param { 'freeze' } type - 'freeze'.
* @param { FreezeObserver } observer - The freeze event 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
* @atomicservice
* @since 18
*/
function on(type: 'freeze', observer: FreezeObserver): void;
/**
* Unregister the observer for freeze event.
* This function can only be called from main thread.
*
* @param { 'freeze' } type - 'freeze'.
* @param { FreezeObserver } observer - The freeze event observer.
* @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
* 2. Incorrect parameter types; 3. Parameter verification failed.
* @throws { BusinessError } 16300004 - The observer does not exist.
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
function off(type: 'freeze', observer?: FreezeObserver): void;
/**
* Set the default exception handler, This function will be excuted right after the callback function registered
* through errorManger.on is executed. You can use it to implement chain calls instead of errorManager.on.
* This API must be called in the main thread.
*
* @param { ErrorHandler } [defaultHandler] - the default error handler.
* @returns { ErrorHandler } return original default handler.
* @throws { BusinessError } 16000205 - The API is not called in the main thread.
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 21
* @arkts 1.1
*/
function setDefaultErrorHandler(defaultHandler?: ErrorHandler): ErrorHandler;
/**
* The observer will be called by system when an error occurs.
*
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @since 9
*/
/**
* The observer will be called by system when an error occurs.
*
* @typedef { _ErrorObserver.default }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @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 19
*/
export type ErrorObserver = _ErrorObserver.default;
/**
* The observer will be called when application main thread execute timeout.
*
* @typedef { _LoopObserver }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 12
*/
/**
* The observer will be called when application main thread execute timeout.
*
* @typedef { _LoopObserver }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @crossplatform
* @atomicservice
* @since 19
*/
export type LoopObserver = _LoopObserver;
/**
* 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<any> } promise - the promise that is rejected
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @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<any> } promise - the promise that is rejected
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @crossplatform
* @atomicservice
* @since 19
*/
export type UnhandledRejectionObserver = (reason: Error | any, promise: Promise<any>) => void;
/**
* The observer will be called by system when freeze happens.
*
* @typedef { function }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 18
*/
export type FreezeObserver = () => void;
/**
* ErrorHandler will be called when ArkTS runtime throws an exception which doesn't caught by user.
*
* @typedef { function }
* @param { Error} errObject - the error object about the exception.
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @atomicservice
* @since 21
* @arkts 1.1
*/
export type ErrorHandler = (errObject: Error) => void;
}
export default errorManager;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/interface_sdk-js.git
git@gitee.com:openharmony/interface_sdk-js.git
openharmony
interface_sdk-js
interface_sdk-js
master

搜索帮助