catching<T, E extends Object> static method
Creates a success result from the return value of an
async closure
. Without an explicit type
parameters, any object thrown by closure
is caught
and returned in a failure result. Specifying the
type parameters will catch only objects of type E
.
All others continue uncaught. To specify E
Dart
requires that you also specify T
.
Implementation
static FutureOr<Result<T, E>> catching<T, E extends Object>(
FutureOr<T> Function() closure) async {
try {
final value = await closure();
return Result.success(value);
} on E catch (e) {
return Result.failure(e);
}
}