Last active
November 27, 2019 18:07
-
-
Save legalcodes/25ade03f0632878a9169209e3cd7bef2 to your computer and use it in GitHub Desktop.
handle_errors_example
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
void printOrderMessage () async { | |
try { | |
var order = await fetchUserOrder(); | |
print('Awaiting user order...'); | |
print(order); | |
} catch (err) { | |
print('Caught error: $err'); | |
} | |
} | |
Future<String> fetchUserOrder() { | |
// Imagine that this function is more complex. | |
var str = Future.delayed(Duration(seconds: 4), () => throw 'Cannot locate user order'); | |
return str; | |
} | |
Future<void> main() async { | |
await printOrderMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment