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

HarmonyOS
2024-12-11 09:44:42
浏览
收藏 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}`);

      }

    });

  }

}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
分享
微博
QQ
微信
回复
2024-12-11 11:51:07
相关问题