Runs body in its own zone.
If onError is non-null the zone is considered an error zone. All uncaught errors, synchronous or asynchronous, in the zone are caught and handled by the callback.
Errors may never cross error-zone boundaries. This is intuitive for leaving a zone, but it also applies for errors that would enter an error-zone. Errors that try to cross error-zone boundaries are considered uncaught.
var future = new Future.value(499);
runZoned(() {
future = future.then((_) { throw "error in first error-zone"; });
runZoned(() {
future = future.catchError((e) { print("Never reached!"); });
}, onError: (e) { print("unused error handler"); });
}, onError: (e) { print("catches error of first error-zone."); });
Example:
runZoned(() {
new Future(() { throw "asynchronous error"; });
}, onError: print); // Will print "asynchronous error".