Spec-Zone.ru › Dart 2

dart:async

свойство errorZone

Zone errorZone

Зона ошибок отвечает за обработку неперехваченных ошибок.

Это ближайшая родительская зона данной зоны, в которой есть метод handleUncaughtError.

Асинхронные ошибки в futures никогда не пересекают границы зон между зонами с разными обработчиками ошибок.

Пример:

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"; });
}

Обратите внимание, что ошибки также не могут попасть в дочернюю зону с другим обработчиком ошибок:

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"); });
}

Реализация

Zone get errorZone;

© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.19.6/dart-async/Zone/errorZone.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API