Is there any rethrow (not throw) equivalent for futures in dart?
myFunc()
.then(processValue)
.catchError(handleError);
Is there any rethrow (not throw) equivalent for futures in dart?
myFunc()
.then(processValue)
.catchError(handleError);
Yes.
If the handleError of a catchError throws the same error object again (because it acts the same way as then's onError), it is considered a "rethrow" and it will also retain the original stack trace.
If you just want to catch some types of errors, and rethrow the rest, you can use the test parameter of catchError:
myFunc()
.then(processValue)
.catchError(handleError, test: (e) => e is MyException);
This only catches MyException exceptions and lets any other error pass through, with no need for you to rethrow them. The test can do any testing, not just type checks.
Also, if you use async functions, you can just use rethrow:
...) async {
try {
var processValue = await myFunc();
....
} catch (e) {
if (something(e)) {
whatnot();
} else {
rethrow;
}
}