Open tetkin-g opened 3 years ago
Good catch. We can fix this by having the example catch some fictitious type that downloadTeam()
would theoretically throw, like:
Future<int> countActivePlayers(String teamName) async {
try {
var team = await downloadTeam(teamName);
if (team == null) return 0;
var players = await team.roster;
return players.where((player) => player.isActive).length;
} on DownloadException catch (e) { // <----
log.error(e);
return 0;
}
}
In Effective Dart, the guideline about preferring async/await over raw futures includes this as an example of good code:
However it violates the guideline about catches without
on
clauses.