Skip to content

Instantly share code, notes, and snippets.

View madmag77's full-sized avatar

Goncharov Artem madmag77

View GitHub Profile
@madmag77
madmag77 / dart_sync_exceptions.dart
Last active March 2, 2021 06:16
[Dart article] Handling exceptions in synchronous code
try {
final _ = 100 ~/ 0;
} on IntegerDivisionByZeroException {
print('Cant divide to zero');
} finally {
print('Clean-up done 1');
}
print('\n\n');
@madmag77
madmag77 / dart_async_exceptions1.dart
Created March 2, 2021 06:30
[Dart article] Async code exceptions 1
try {
Future.delayed(Duration(seconds: 1), () {
final _ = 100 ~/ 0;
});
print('Everything is fine!');
} on IntegerDivisionByZeroException {
print('Cant divide to zero');
} finally {
print('Clean-up done');
}
@madmag77
madmag77 / dart_async_exceptions2.dart
Created March 2, 2021 06:38
[Dart article] Async code exceptions 2
try {
await Future.delayed(Duration(seconds: 1), () {
final _ = 100 ~/ 0;
});
print('Everything is fine!');
} on IntegerDivisionByZeroException {
print('Cant divide to zero');
} finally {
print('Clean-up done');
}
@madmag77
madmag77 / dart_async_axceptions3.dart
Created March 2, 2021 06:44
[Dart article] Async code exceptions 3
try {
await Future.delayed(Duration(seconds: 1), () {
print('Its ok so far');
}).then((value) {
final _ = 100 ~/ 0;
});
print('Everything is fine!');
} on IntegerDivisionByZeroException {
print('Cant divide to zero');
} finally {
@madmag77
madmag77 / dart_async_axceptions4.dart
Created March 2, 2021 06:47
[Dart article] Async code exceptions 4
await Future.delayed(Duration(seconds: 1), () {
print('Its ok so far');
}).then((value) {
final _ = 100 ~/ 0;
}).catchError((error) {
print('Cant divide to zero');
}).whenComplete(() {
print('Clean-up done');
});
@madmag77
madmag77 / dart_async_axceptions5.dart
Created March 2, 2021 06:49
[Dart article] Async code exceptions 5
await Future.delayed(Duration(seconds: 1), () {
print('Its ok so far');
}).then((value) {
final _ = 100 ~/ 0;
}).catchError((error) {
print('Cant divide to zero');
}).whenComplete(() {
print('Clean-up done');
throw 'ss';
}).catchError((error) {
@madmag77
madmag77 / dart_async_axceptions6.dart
Created March 2, 2021 06:51
[Dart article] Async code exceptions 6
await Future.delayed(Duration(seconds: 1), () {
print('Its fie so far');
}).then((value) {
print('Then started');
throw 'random exception';
}).catchError((error) {
print('Cant divide to zero');
}, test: (e) => e is IntegerDivisionByZeroException).catchError((error) {
print('All other exceptions: $error');
}, test: (e) => true).whenComplete(() {
@madmag77
madmag77 / dart_async_axceptions7.dart
Created March 2, 2021 06:55
[Dart article] Async code exceptions 7
try {
await Future.delayed(Duration(seconds: 1), () {
print('Its fie so far');
});
await Future(() {
print('Then started');
throw 'random exception';
});
} on IntegerDivisionByZeroException {
print('Cant divide to zero');
@madmag77
madmag77 / dart_async_axceptions8.dart
Created March 5, 2021 09:23
[Dart article] Async code exceptions 8
try {
Timer.run(() {
print('Timer runs.');
throw Exception('[Timer] Bad thing happens!');
});
print('Everything is fine!');
} on IntegerDivisionByZeroException {
print('Cant divide to zero');
} finally {
print('Clean-up done');
@madmag77
madmag77 / dart_zones1.dart
Created March 5, 2021 09:58
[Dart article] Guarded zones 1
runZonedGuarded((){
Timer.run(() {
print('Timer runs.');
throw Exception('[Timer] Bad thing happens!');
});
print('Everything is fine!');
}, (e,s) {
print('Exception handled $e, \n$s');
});