Skip to content

Commit 3e2a94b

Browse files
committed
docs(flutter): Document Sentry.runZonedGuarded
1 parent b92ae50 commit 3e2a94b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed
Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
<PlatformContent includePath="capture-error/dart.mdx" />
22

3-
- Flutter-specific errors, such as using `FlutterError.onError`, are captured automatically
4-
- The SDK already runs your init `callback` on an error handler, such as [`runZonedGuarded`](https://api.flutter.dev/flutter/dart-async/runZonedGuarded.html) on Flutter versions prior to `3.3`, or [`PlatformDispatcher.onError`](https://api.flutter.dev/flutter/dart-ui/PlatformDispatcher/onError.html) on Flutter versions 3.3 and higher, so that errors are automatically captured.
3+
### FlutterError.onError
4+
5+
Flutter-specific errors, such as using `FlutterError.onError`, are captured automatically.
6+
7+
### PlatformDispatcher.onError / runZonedGuarded
8+
9+
The SDK already runs your init `callback` on an error handler, such as [`runZonedGuarded`](https://api.flutter.dev/flutter/dart-async/runZonedGuarded.html) on Flutter versions prior to `3.3`, or [`PlatformDispatcher.onError`](https://api.flutter.dev/flutter/dart-ui/PlatformDispatcher/onError.html) on Flutter versions 3.3 and higher, so that errors are automatically captured.
10+
11+
If you need a custom error handling zone which also provides automatic error reporting and breadcrumb tracking, use `Sentry.runZonedGuarded`. It wraps Dart's native [`runZonedGuarded`](https://api.flutter.dev/flutter/dart-async/runZonedGuarded.html) function with Sentry-specific functionality.
12+
13+
This function automatically records calls to `print()` as `Breadcrumbs` and can be configured using `SentryOptions.enablePrintBreadcrumbs`.
14+
15+
```dart
16+
Sentry.runZonedGuarded(() {
17+
WidgetsBinding.ensureInitialized();
18+
19+
// Errors before init will not be handled by Sentry
20+
21+
SentryFlutter.init(
22+
(options) {
23+
...
24+
},
25+
appRunner: () => runApp(MyApp()),
26+
);
27+
} (error, stackTrace) {
28+
// Automatically sends errors to Sentry, no need to do any
29+
// captureException calls on your part.
30+
// On top of that, you can do your own custom stuff in this callback.
31+
});
32+
```

0 commit comments

Comments
 (0)