ohos.app.ability.error_manager
Note:
Currently in the beta phase.
The ErrorManager provides capabilities for managing Ability errors, including listening to and unregistering from error events.
Import Module
import kit.AbilityKit.*
Permission List
ohos.permission.DISTRIBUTED_DATASYNC
ohos.permission.PREPARE_APP_TERMINATE
ohos.permission.PRIVACY_WINDOW
Usage Instructions
API example code usage instructions:
- If the first line of example code contains a "// index.cj" comment, it indicates the example can be compiled and run in the "index.cj" file of a Cangjie template project.
- If the example requires obtaining the Context application context, it needs to be configured in the "main_ability.cj" file of the Cangjie template project.
For the aforementioned example projects and configuration templates, refer to Cangjie Example Code Instructions.
class ErrorManager
public class ErrorManager {}
Description: Provides capabilities for managing Ability errors, including listening to and unregistering from error events.
System Capability: SystemCapability.Ability.AbilityRuntime.Core
Since: 22
static func off(ErrorManagerEvent, Int32)
public static func off(eventType: ErrorManagerEvent, observerId: Int32): Unit
Description: Unregisters from listening to Ability error events.
System Capability: SystemCapability.Ability.AbilityRuntime.Core
Since: 22
Parameters:
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| eventType | ErrorManagerEvent | Yes | - | Error event type. |
| observerId | Int32 | Yes | - | Observer ID. |
Exceptions:
-
BusinessException: Corresponding error codes are listed below. For details, see Ability Subsystem Error Codes.
Error Code ID Error Message 16000003 The specified ID does not exist.
Example:
// index.cj
import kit.AbilityKit.*
import kit.PerformanceAnalysisKit.*
import ohos.business_exception.BusinessException
try {
let observerId: Int32 = 1
ErrorManager.off(ErrorManagerEvent.Error, observerId)
} catch (e: BusinessException) {
Hilog.info(0, "test_errorManager", "${e.message}")
}
static func on(ErrorManagerEvent, ErrorObserver)
public static func on(eventType: ErrorManagerEvent, observer: ErrorObserver): Int32
Description: Listens to Ability error events.
System Capability: SystemCapability.Ability.AbilityRuntime.Core
Since: 22
Parameters:
| Parameter Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| eventType | ErrorManagerEvent | Yes | - | Error event type. |
| observer | ErrorObserver | Yes | - | Error observer. |
Return Value:
| Type | Description |
|---|---|
| Int32 | Observer ID. |
Exceptions:
-
BusinessException: Corresponding error codes are listed below. For details, see Ability Subsystem Error Codes.
Error Code ID Error Message 16000003 The specified ID does not exist.
Example:
// index.cj
import kit.AbilityKit.*
import ohos.business_exception.BusinessException
import kit.PerformanceAnalysisKit.Hilog
try {
let observer = ErrorObserver(
{
errorMsg =>
Hilog.info(0, "test_errorManager", "onUnhandledException, errorMsg: =${errorMsg}")
},
onException: Some({ errorObj =>
Hilog.info(0, "test_errorManager", "onException, name: =${errorObj.name}")
Hilog.info(0, "test_errorManager", "onException, message: =${errorObj.message}")
if (let Some(v) <-errorObj.stack) {
Hilog.info(0, "test_errorManager", "onException, stack: =${v}")
}
})
)
ErrorManager.on(ErrorManagerEvent.Error, observer)
} catch (e: BusinessException) {
Hilog.info(0, "test", "${e.message}")
}
enum ErrorManagerEvent
public enum ErrorManagerEvent {
| Error
| ...
}
Description: Error management event types.
System Capability: SystemCapability.Ability.AbilityRuntime.Core
Since: 22
Error
Error
Description: Error event.
System Capability: SystemCapability.Ability.AbilityRuntime.Core
Since: 22