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();
}
tryandcatchyour code would not continue executing, but continuing in thecatchblock after an exception is thrown. However, it will continue if you catch it like you proposed.