guard<T> static method
T?
guard<T>(
- T callback()
Runs callback in a zone where unhandled errors from LiveTests are
caught and dispatched to the appropriate Invoker.
Implementation
static T? guard<T>(T Function() callback) => runZoned<T?>(
callback,
zoneSpecification: ZoneSpecification(
// Use [handleUncaughtError] rather than [onError] so we can
// capture [zone] and with it the outstanding callback counter for
// the zone in which [error] was thrown.
handleUncaughtError: (self, _, zone, error, stackTrace) {
var invoker = zone[#test.invoker] as Invoker?;
if (invoker != null) {
self.parent!.run(() => invoker._handleError(zone, error, stackTrace));
} else {
self.parent!.handleUncaughtError(error, stackTrace);
}
},
),
);