5

I have my Sentry setup like this:

void main() => runZonedGuarded(() {
  runApp(MyApp());
}, (Object error, StackTrace stackTrace) {
  reportError(error, stackTrace);
});

and related functions

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


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

I added throw Exception("my-error") inside a widget's build method, I can't see the error is showing on the Sentry web console.

I create a single file to throw exception and sentry capture, and I do see sentry is reporting the error.

Something must wrong with runZonedGuarded.

2
  • I have the same problem. Did you find a solution?
    – RaSha
    Sep 4, 2020 at 16:16
  • For me it was a problem in the private network in which I used Sentry.
    – RaSha
    Sep 14, 2020 at 13:54

4 Answers 4

2

After a number of Sentry setups that didn't seem to work right, I arrived at this one that works:

Future<void> main() async {
  final sentry = Sentry.SentryClient(Sentry.SentryOptions(dsn: '[Add dsn URI here]'));

  runZonedGuarded(() {
    WidgetsFlutterBinding.ensureInitialized();

    FlutterError.onError = (FlutterErrorDetails errorDetails) {
      sentry.captureException(
        errorDetails.exception,
        stackTrace: errorDetails.stack,
      );
    };

    runApp(MyApp());
  }, (Object error, StackTrace stackTrace) {
    sentry.captureException(
      error,
      stackTrace: stackTrace,
    );
  });
}
1

Check in your sentry dashboard if you are using the free version and if the monthly quota hasnt been surpassed. If that is the case you will not receive any events.

1
  • 1
    I thought something had errored in our codebase at work but it was this. After a day of debugging this solved it for me! Thanks!
    – omeanwell
    Jan 8, 2021 at 15:19
0
  1. you must make the func async to send error to sentry console
  2. be sure import this file for mobile app:
    import 'package:sentry/io_client.dart';
    E.g:

main.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,
    );
  }
}

HomeScreen

floatingActionButton: FloatingActionButton(
          onPressed: () async{

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

          },
0
0

By the way in release version it will send every exception, because in debug flutter doesn't catch every error that displays in the console, and to simplify that for you can use one of these packages :

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.