🐞 Catch Exceptions In Flutter With Catcher & Sentry
Published On: Dec 13 '19
🐞 Catch Exceptions In Flutter With Catcher & Sentry

Who doesn't hate unhandled exceptions in their applications?

In this post, I will show you how to catch unhandled exceptions in a flutter application using a Catcher plugin and sentry.io

Create a new project in Sentry

Go to sentry.io and create a new project

Create New Project

We can just use the DSN for our application.


Install Catcher

Open your app's pubspec.yml file and add catcher as a dependency.

  catcher: ^0.2.7

NOTE: Catcher version mentioned in this post may not be the latest version.

And in your main.dart file,

Import the package,

import 'package:catcher/catcher_plugin.dart';




void main() {
  /// checking if release mode or not
  /// no need of Catcher & Sentry in debug mode.
  if (kReleaseMode) {
      releaseConfig: CatcherOptions(
  } else {

Replace your sentry DSN with <SENTRY_DSN_STRING> in SentryHandler

In CatcherOptions, we have to provide a ReportMode as the first parameter and at least one ReportHandler as the second parameter. Here we are using SilentReportMode() as ReportMode and SentryHandler() as error handler.

What we are expecting here is, if there is any unhandled exception occurs, the app will send the error report to sentry silently. If you want to get user's confirmation to send an error report, you can use DialogReportMode() instead of SilentReportMode().

You can refer more in the plugin documentation here

next, in MaterialApp widget add Catcher.navigatorKey as value of navigatorKey property

class App extends StatelessWidget {

  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: Catcher.navigatorKey, // <---------
      home: RootPage(),

And that's it!

Catcher will catch all the unhandled exceptions in the application from now on. You can view the exceptions in the sentry dashboard.