ErrorCallbackHandler typedef

ErrorCallbackHandler = AsyncError? Function(Zone self, ZoneDelegate parent, Zone zone, Object error, StackTrace? stackTrace)

The type of a custom Zone.errorCallback implementation function.

The error and stackTrace are the error and stack trace passed to Zone.errorCallback of zone.

The function will be called when a synchronous error becomes an asynchronous error, either by being caught, for example by a Future.then callback throwing, or when used to create an asynchronous error programmatically, for example using Future.error or Completer.complete.

If the function does not want to replace the error or stack trace, it should just return parent.errorCallback(zone, error, stackTrace), giving the parent zone the chance to intercept.

If the function does want to replace the error and/or stack trace, say with error2 and stackTrace2, it should still allow the parent zone to intercept those errors, for examples as:

  return parent.errorCallback(zone, error, stackTrace) ??
      AsyncError(error, stackTrace);

The function returns either null if the original error and stack trace is unchanged, avoiding any allocation in the most common case, or an AsyncError containing a replacement error and stack trace which will be used in place of the originals as the asynchronous error.

The self Zone is the zone the handler was registered on, the parent delegate forwards to the handlers of self's parent zone, and zone is the current zone where the error was uncaught, which will have self as an ancestor zone.

The error callback handler must not throw.

The function must only access zone-related functionality through self, parent or zone. It should not depend on the current zone (Zone.current).

Implementation

typedef ErrorCallbackHandler =
    AsyncError? Function(
      Zone self,
      ZoneDelegate parent,
      Zone zone,
      Object error,
      StackTrace? stackTrace,
    );