errorZone property Null safety
The error zone is responsible for dealing with uncaught errors.
This is the closest parent zone of this zone that provides a handleUncaughtError method.
Asynchronous errors in futures never cross zone boundaries between zones with different error handlers.
Example:
import 'dart:async';
main() {
var future;
runZonedGuarded(() {
// The asynchronous error is caught by the custom zone which prints
// 'asynchronous error'.
future = Future.error("asynchronous error");
}, (error) { print(error); }); // Creates a zone with an error handler.
// The following `catchError` handler is never invoked, because the
// custom zone created by the call to `runZonedGuarded` provides an
// error handler.
future.catchError((error) { throw "is never reached"; });
}
Note that errors cannot enter a child zone with a different error handler either:
import 'dart:async';
main() {
runZonedGuarded(() {
// The following asynchronous error is *not* caught by the `catchError`
// in the nested zone, since errors are not to cross zone boundaries
// with different error handlers.
// Instead the error is handled by the current error handler,
// printing "Caught by outer zone: asynchronous error".
var future = Future.error("asynchronous error");
runZonedGuarded(() {
future.catchError((e) { throw "is never reached"; });
}, (error, stack) { throw "is never reached"; });
}, (error, stack) { print("Caught by outer zone: $error"); });
}
Implementation
Zone get errorZone;