Reputation: 1663
try {
final result = await http.get(pingUrl)
.catchError((e) => print(e));
return result;
} catch (e) {
print(e)
}
Why I can't handle exception here in catch block?
Upvotes: 0
Views: 55
Reputation: 924
No, because you are catching in Future.
You shouldn't cath in future:
try {
final result = await http.get(pingUrl);
// .catchError((e) => print(e)); <- removed
return result;
} catch (e) {
print(e)
}
Or throw again in catchError:
try {
final result = await http.get(pingUrl)
.catchError((e) {
print(e);
throw foo;
});
return result;
} catch (e) {
print(e)
}
I prefer the first option.
Upvotes: 1