Last active
December 3, 2020 19:54
-
-
Save kevmoo/c8deb87cee33b48316fc0f5cf4b1891f to your computer and use it in GitHub Desktop.
Example of dart-lang/linter#2357
This file contains hidden or 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
Future<void> main() async { | |
for (var func in [goodCatch, badCatch]) { | |
print('Running $func'); | |
try { | |
await func(); | |
} catch (e) { | |
print('Why was this not caught? $e'); | |
} | |
print(''); | |
} | |
} | |
Future<void> goodCatch() async { | |
try { | |
// `await` here is CRITICAL! | |
return await badAsync(); | |
} on StateError catch (e) { | |
print('Caught "$e"!'); | |
} | |
} | |
Future<void> badCatch() async { | |
try { | |
// No await, so the state error is not caught! | |
return badAsync(); | |
} on StateError catch (e) { | |
print('Caught "$e"!'); | |
} | |
} | |
Future<void> badAsync() async { | |
throw StateError('bad!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment