#鸿蒙通关秘籍#如何模拟一个appCrash?

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
IDE红尘旧梦
import { common } from '@kit.AbilityKit';

import { BusinessError } from '@kit.BasicServicesKit';

@Entry

@Component

struct Index {

  @State message: string = '111';

  context = getContext(this) as common.UIAbilityContext

  build() {

    Button("appCrash").onClick(() => {

      try {

        this.context.terminateSelf((err: BusinessError) => {

          if (err.code) {

            console.error(`terminateSelf failed, code is \${err.code}, message is \${err.message}`);

            return;

          }
          console.info('terminateSelf succeed');

        });

      } catch (err) {

        let code = (err as BusinessError).code;

        let message = (err as BusinessError).message;

        console.error(`terminateSelf failed, code is \${code}, message is \${message}`);

      }

    });

  }

}
分享
微博
QQ
微信
回复
1天前
相关问题
实现一个模拟文件下载的过程
332浏览 • 1回复 待解决