Spec-Zone.ru › Dart 2

dart:async

Свойство errorZone

Zone errorZone

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

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

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

Пример:

import 'dart:async';

main() {
  var future;
  runZoned(() {
    // The asynchronous error is caught by the custom zone which prints
    // 'asynchronous error'.
    future = Future.error("asynchronous error");
  }, onError: (e) { print(e); });  // Creates a zone with an error handler.
  // The following `catchError` handler is never invoked, because the
  // custom zone created by the call to `runZoned` provides an
  // error handler.
  future.catchError((e) { throw "is never reached"; });
}

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

import 'dart:async';

main() {
  runZoned(() {
    // 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");
    runZoned(() {
      future.catchError((e) { throw "is never reached"; });
    }, onError: (e) { throw "is never reached"; });
  }, onError: (e) { print("Caught by outer zone: $e"); });
}

Реализация

Zone get errorZone;

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

Spec-Zone.ru

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