void main() {
foo().catchError((error) {
print('Error caught = $error');
});
}
Future<void> foo() {
throw Future.error('FooError');
}
As I read the docs:
This is the asynchronous equivalent of a "catch" block.
If I use catch
block, the error is caught. But my catchError
isn't able to catch the error, but according to docs it should. Am I doing something wrong?
Note: I know I can use return
instead of throw
and the error will be then caught in catchError
as stated by @CopsOnRoad here. My question is why catchError
isn't catching a thrown error but catch
block does catch that.