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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。