参考下面的示例代码:import { common } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component struct Index { @State message: string = 'Hello World'; context = getContext(this) as common.UIAbilityContext build() { Button("appCrash").onClick(()=>{ try { this.context.terminateSelf((err: BusinessError) => { if (err.code) { // 处理业务逻辑错误 return; } // 执行正常业务 }); } catch (err) { // 捕获同步的参数错误 let code = (err as BusinessError).code; let message = (err as BusinessError).message; } }) } }
参考下面的示例代码: