runZonedGuarded<R> static method
dynamic
runZonedGuarded<R>(
- R body(),
- void onError(
- Object error,
- StackTrace stack
- Map<
Object?, Object?> ? zoneValues, - ZoneSpecification? zoneSpecification,
Creates a new error handling zone with Sentry integration using runZonedGuarded.
This method provides automatic error reporting and breadcrumb tracking while allowing you to define a custom error handling zone. It wraps Dart's native runZonedGuarded function with Sentry-specific functionality.
This function automatically records calls to print()
as Breadcrumbs and
can be configured using SentryOptions.enablePrintBreadcrumbs.
Sentry.runZonedGuarded(() {
WidgetsBinding.ensureInitialized();
// Errors before init will not be handled by Sentry
SentryFlutter.init(
(options) {
...
},
appRunner: () => runApp(MyApp()),
);
} (error, stackTrace) {
// Automatically sends errors to Sentry, no need to do any
// captureException calls on your part.
// On top of that, you can do your own custom stuff in this callback.
});
Implementation
static runZonedGuarded<R>(
R Function() body,
void Function(Object error, StackTrace stack)? onError, {
Map<Object?, Object?>? zoneValues,
ZoneSpecification? zoneSpecification,
}) =>
SentryRunZonedGuarded.sentryRunZonedGuarded(
_hub,
body,
onError,
zoneValues: zoneValues,
zoneSpecification: zoneSpecification,
);