I write a lot of async code that uses await
to handle Futures
.
If I have
() async {
var result = await someFuture();
}
what would be the preferred way to catch errors. Wraping the code in try/catch or doing
() async {
var result = await someFuture().catch(_errorHandler);
}
EDIT:
Also, if I have many await calls in one async method, what is the preferred catch all the errors instead of writing .catchError
for eachOne.
() async {
var result = await someFuture();
var result2 = await someFuture2();
var result3 = await someFuture3();
}
According to the Dart docs if you use await wrap it in a try-catch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With