提交 a949cca2 编写于 作者: X xinking129

add interface documentation description

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 9120b22a
......@@ -24,6 +24,7 @@
| 接口名称 | 说明 |
| ------------------------------ | ------------------------------------------------------------ |
| onUnhandledException(errMsg: string): void | 系统回调接口,应用注册后,当应用产生未捕获的异常时的回调。 |
| onException?(errObject: Error): void | 系统回调接口,应用注册后,当应用底层需要通知上层js异常事件时的回调。 |
### 解除注册结果码
......@@ -44,6 +45,14 @@ let callback = {
onUnhandledException: function (errMsg) {
console.log(errMsg);
}
onException: function (errObject) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObject.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
}
export default class EntryAbility extends UIAbility {
......
......@@ -39,6 +39,14 @@ let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg);
}
onException(errorObj) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObject.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
};
let observerId = -1;
try {
......
......@@ -33,3 +33,42 @@ try {
console.error('registerErrorObserver failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
}
```
## ErrorObserver.onException
onException?(errObject: Error): void;
当Native层发生异常事件并且需要通知js层时调用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| errObject | Error | 否 | 有关于异常事件名字、消息和错误堆栈信息的对象。 |
**示例:**
```ts
import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.error('onUnhandledException, errorMsg: ', errorMsg);
}
onException(errObject) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObject.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
};
try {
errorManager.on('error', observer);
} catch (error) {
console.error('registerErrorObserver failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册