runWithDiagnosticsZone<T> method

T runWithDiagnosticsZone<T>(
  1. T body(), {
  2. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Implementation

T runWithDiagnosticsZone<T>(
  T Function() body, {
  void Function(Object error, StackTrace stackTrace)? onError,
}) {
  T? result;
  runZonedGuarded(
    () {
      result = body();
    },
    (error, stackTrace) {
      recordUnhandledError(error, stackTrace, source: 'Zone');
      onError?.call(error, stackTrace);
    },
    zoneSpecification: capturePrint
        ? ZoneSpecification(
            print: (self, parent, zone, line) {
              recordDebugLog(line, source: 'print');
              parent.print(zone, line);
            },
          )
        : null,
  );
  return result as T;
}