Skip to content

Instantly share code, notes, and snippets.

@Jonas-Sander
Created December 21, 2019 22:58
Show Gist options
  • Save Jonas-Sander/7ef4bdd7948b2c9b5d6912826eca3541 to your computer and use it in GitHub Desktop.
Save Jonas-Sander/7ef4bdd7948b2c9b5d6912826eca3541 to your computer and use it in GitHub Desktop.
Dart async throwing
/*Will print:
Uncaught Error: Instance of 'SomeException'
will catch this
bye bye
*/
void main() {
test();
}
Future<void> test() async {
try {
asyncThrowing();
} catch (_) {
print('will not catch this');
}
try {
await asyncThrowing();
} catch (_) {
print('will catch this');
}
print('bye bye');
}
Future<void> asyncThrowing() async {
throw SomeException();
}
class SomeException implements Exception {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment