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.


Solution 1: khlewe

  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.');

          },


Solution 2: khlewe

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 :


Solution 3: Pedro R.

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.


Solution 4: jon

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