harmony 鸿蒙GlobalObserver

  • 2025-06-12
  • 浏览 (4)

GlobalObserver

The GlobalObserver module defines an exception observer. It can be used as an input parameter in ErrorManager.on(‘globalErrorOccurred’) and ErrorManager.on(‘globalUnhandledRejectionDetected’) to listen for event processing of the current application’s main thread.

NOTE

The initial APIs of this module are supported since API version 16. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { errorManager } from '@kit.AbilityKit';

Properties

Atomic service API: This API can be used in atomic services since API version 16.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
reason GlobalError Yes Object related to the exception event name, message, error stack information, exception thread name, and exception thread type.

Example

import { errorManager } from '@kit.AbilityKit';

function errorFunc(observer: errorManager.GlobalError) {
    console.log("result name :" + observer.name);
    console.log("result message :" + observer.message);
    console.log("result stack :" + observer.stack);
    console.log("result instanceName :" + observer.instanceName);
    console.log("result instaceType :" + observer.instanceType);
}

errorManager.off('globalErrorOccurred', errorFunc)

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

0  赞