dart:async
库中Zone.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"); });
}
相关用法
- Dart Zone.bindUnaryCallbackGuarded用法及代码示例
- Dart Zone.bindCallback用法及代码示例
- Dart Zone.bindUnaryCallback用法及代码示例
- Dart Zone.bindCallbackGuarded用法及代码示例
- Dart Zone.bindBinaryCallback用法及代码示例
- Dart Zone.bindBinaryCallbackGuarded用法及代码示例
- Dart Zone.runGuarded用法及代码示例
- Dart Zone.print用法及代码示例
- Dart ZLibEncoder.memLevel用法及代码示例
- Dart ZLibCodec.memLevel用法及代码示例
- Dart MapMixin.containsKey用法及代码示例
- Dart Iterator用法及代码示例
- Dart AttributeClassSet.intersection用法及代码示例
- Dart num.sign用法及代码示例
- Dart TransformList.last用法及代码示例
- Dart FileList.first用法及代码示例
- Dart CanvasRenderingContext2D.drawImageScaledFromSource用法及代码示例
- Dart FileList.length用法及代码示例
- Dart Iterable.takeWhile用法及代码示例
- Dart LinkedHashMap用法及代码示例
- Dart RegExp.pattern用法及代码示例
- Dart StreamTransformer构造函数用法及代码示例
- Dart JsArray.removeAt用法及代码示例
- Dart ListMixin.expand用法及代码示例
- Dart UriData.parse用法及代码示例
注:本文由纯净天空筛选整理自dart.dev大神的英文原创作品 errorZone property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。