Spec-Zone.ru › Dart 1

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 = new 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 = new 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 Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-async/Zone/errorZone.html

Spec-Zone.ru

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