提交 3a1a3b78 编写于 作者: X xinking129

merge master

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 962f8639
......@@ -24,6 +24,7 @@
| 接口名称 | 说明 |
| ------------------------------ | ------------------------------------------------------------ |
| onUnhandledException(errMsg: string): void | 系统回调接口,应用注册后,当应用产生未捕获的异常时的回调。 |
| onException?(errObject: Error): void | 系统回调接口,应用注册后,当应用产生异常上报js层时的回调。 |
### 解除注册结果码
......@@ -43,6 +44,13 @@ let registerId = -1;
let callback = {
onUnhandledException: function (errMsg) {
console.log(errMsg);
},
onException: function (errorObj) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObj.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
}
......
......@@ -38,6 +38,13 @@ on(type: 'error', observer: ErrorObserver): number;
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(errorObj.stack) === 'string') {
console.log('onException, stack: ', errorObj.stack);
}
}
};
let observerId = -1;
......
......@@ -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;
将在应用运行异常时调用。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| errObject | Error | 是 | 有关异常事件名字、消息和错误堆栈信息的对象。 |
**示例:**
```ts
import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.error('onUnhandledException, errorMsg: ', errorMsg);
},
onException(errorObj) {
console.log('onException, name: ', errorObj.name);
console.log('onException, message: ', errorObj.message);
if (typeof(errorObj.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.
先完成此消息的编辑!
想要评论请 注册