Skip to content

Instantly share code, notes, and snippets.

@riscait
Created June 28, 2022 04:30
Show Gist options
  • Save riscait/105e8c648faee487f6b59892afb45e16 to your computer and use it in GitHub Desktop.
Save riscait/105e8c648faee487f6b59892afb45e16 to your computer and use it in GitHub Desktop.
unawaited vs ignore
import 'dart:async';
Future<void> throwForIgnore() async {
throw Exception('for ignore'); // <- be ignored
}
Future<void> throwForUnawaited() async {
throw Exception('for unawaited');
}
void main() async {
try {
throwForIgnore().ignore();
print('no throw with throwForIgnore');
} on Exception catch (e) {
print(e);
}
try {
unawaited(throwForUnawaited());
print('no throw with throwForUnawaited');
} on Exception catch (e) {
print(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment