createErrorZone function

Zone createErrorZone({
  1. String uncaughtErrorTitle = 'Unhandled exception:',
  2. bool printErrorToStderr = true,
  3. OnUncaughtError? onUncaughtError,
  4. Zone? parentZone,
})

Creates an error Zone.

  • The uncaughtErrorTitle to use when printing error (if onUncaughtError is not provided).
  • If printErrorToStderr is true, prints to STDERR (if onUncaughtError is not provided).
  • onUncaughtError is the function to handle uncaught errors. If not provided, prints error.

See printZoneError.

Implementation

Zone createErrorZone({
  String uncaughtErrorTitle = 'Unhandled exception:',
  bool printErrorToStderr = true,
  OnUncaughtError? onUncaughtError,
  Zone? parentZone,
}) {
  var zoneId = ++_errorZoneIDCount;

  var zoneSpecification = ZoneSpecification(
    handleUncaughtError: (self, parent, zone, error, stackTrace) =>
        _handleUncaughtError(uncaughtErrorTitle, printErrorToStderr,
            onUncaughtError, self, parent, zone, error, stackTrace),
  );

  parentZone ??= Zone.current;

  var zone = parentZone
      .fork(specification: zoneSpecification, zoneValues: {'zoneID': zoneId});
  return zone;
}