Sentry 未在 Flutter 内报告错误

use*_*968 6 sentry flutter

我的哨兵设置如下:

void main() => runZonedGuarded(() {
  runApp(MyApp());
}, (Object error, StackTrace stackTrace) {
  reportError(error, stackTrace);
});
Run Code Online (Sandbox Code Playgroud)

及相关功能

final SentryClient sentry = new SentryClient(dsn: '<my-dsn>');


Future<void> reportError(dynamic error, dynamic stackTrace) async {
  sentry.captureException(
    exception: error,
    stackTrace: stackTrace,
  );
}
Run Code Online (Sandbox Code Playgroud)

throw Exception("my-error")在小部件的构建方法中添加了内容,但我看不到 Sentry Web 控制台上显示的错误。

我创建了一个文件来引发异常和哨兵捕获,并且我确实看到哨兵正在报告错误。

肯定有什么问题runZonedGuarded

小智 1

  1. 您必须使 func 异步才能将错误发送到哨兵控制台
  2. 请务必为移动应用程序导入此文件:
    import 'package:sentry/io_client.dart';
    例如:

主程序.dart

import 'package:sentry/io_client.dart';
final SentryClient sentry = new SentryClient(dsn: YOUR_DSN);

main() async {
  try {
    throw new StateError('This is a Dart exception.');
  } catch(error, stackTrace) {
    await sentry.captureException(
      exception: error,
      stackTrace: stackTrace,
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

主屏幕

floatingActionButton: FloatingActionButton(
          onPressed: () async{

            throw new StateError('This is a Dart exception.');

          },
Run Code Online (Sandbox Code Playgroud)