Skip to content

Instantly share code, notes, and snippets.

@madmag77
Created March 5, 2021 10:10
Show Gist options
  • Save madmag77/3a9baff01f0759a46d76d0338fbd31af to your computer and use it in GitHub Desktop.
Save madmag77/3a9baff01f0759a46d76d0338fbd31af to your computer and use it in GitHub Desktop.
[Dart article] Guarded zones 2
print('Current zone start in: ${Zone.current.toString()}');
runZonedGuarded(() {
print(
'Current zone inside runZoned: ${Zone.current.toString()} with name ${Zone.current['ZoneName']}');
Timer.run(() {
print('Timer runs.');
throw Exception('[Timer] Bad thing happens!');
});
runZonedGuarded(
() {
print(
'Current zone (1) inside runZoned: ${Zone.current.toString()} with name ${Zone.current['ZoneName']}');
Timer.run(() {
print('Timer 1 runs. ');
throw Exception('[Timer 1] Bad thing happens!');
});
},
(e, s) {
print(
'Current zone (1) inside catch: ${Zone.current.toString()} with name ${Zone.current['ZoneName']}');
print('Exception handled (1) $e, \n$s');
},
zoneValues: {'ZoneName': 'Second zone'},
);
print('Everything is fine!');
}, (e, s) {
print(
'Current zone inside catch: ${Zone.current.toString()} with name ${Zone.current['ZoneName']}');
print('Exception handled $e, \n$s');
}, zoneValues: {'ZoneName': 'First zone'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment