Created
December 21, 2019 22:58
-
-
Save Jonas-Sander/7ef4bdd7948b2c9b5d6912826eca3541 to your computer and use it in GitHub Desktop.
Dart async throwing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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