runZoneGuardedWithLogging method

Future<void>? runZoneGuardedWithLogging(
  1. FutureCallback onRun, {
  2. void onError(
    1. Object,
    2. StackTrace
    )?,
  3. Map<Object?, Object?>? zoneValues,
  4. ZoneSpecification? zoneSpecification,
})

This can be used to catch errors in a zone. ometimes, errors are instead caught by Zones. A common case where relying on Flutter to catch errors would not be enough is when an exception happens inside the onPressed handler of a button.

Implementation

Future<void>? runZoneGuardedWithLogging(
  FutureCallback onRun, {
  void Function(Object, StackTrace)? onError,
  Map<Object?, Object?>? zoneValues,
  ZoneSpecification? zoneSpecification,
}) {
  return runZonedGuarded<Future<void>>(
    onRun,
    onError ??
        (error, stack) {
          onRecordError(
            error,
            stack,
            fatal: true,
          );
        },
    zoneValues: zoneValues,
    zoneSpecification: zoneSpecification,
  );
}