flutter 崩溃收集

本文详细介绍了Flutter应用的崩溃收集方法,包括通用的try/catch、Future API的错误处理、runZoned、FlutterError.onError以及Isolate.current.addErrorListener。同时,探讨了Flutter异常收集的最佳实践,并对比了Sentry和Crashlytics这两个流行的崩溃收集平台,讨论了它们的优缺点以及官方支持和第三方插件的使用情况。Sentry虽然易于接入但免费版有限制,而Crashlytics虽为免费但目前Flutter官方尚无直接支持的包。
摘要由CSDN通过智能技术生成

目录

 

一、flutter 崩溃收集的方式

1、通用方式

2、捕捉async异常

1)try/catch

2)使用 Future API 

         3)async异常 与 Future 的更多信息

3、使用 runZoned

4、使用 FlutterError.onError

5、使用 Isolate.current.addErrorListener

二、Flutter异常收集最佳实践

三、Flutter crash 收集平台

1、Sentry

1)商业Sentry服务器

2)flutter官方支持

3)总结

2、Crashlytics (--> fabric --> Firebase)

1)flutter 官方支持的计划

2)非官方flutter插件

3)总结


 

一、flutter 崩溃收集的方式

 

1、通用方式

use a try/catch block

 

2、捕捉async异常

1)try/catch

Future main() async {
  var dir = new Directory('/tmp');

  try {
    var dirList = dir.list();
    await for (FileSystemEntity f in dirList) {
      if (f is File) {
        print('Found file ${f.path}');
      } else if (f is Directory) {
        print('Found dir ${f.path}');
      }
    }
  } catch (e) {
    print(e.toString());
  }
}

 

2)使用 Future API 

myFunc()
  .then((value) {
    doSomethingWith(value);
    ...
    throw("some arbitrary error");
  })
  .catchError(handleError);

 

3)async异常 与 Future 的更多信息

 

 

3、使用 runZoned

// This creates a [Zone] that contains the Flutter application and stablishes
// an error handler that captures errors and reports them.
//
// Using 
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值