runCatching<R> method
FutureOr<R?>
runCatching<R>(
- FutureOr<
R?> block(), { - FutureOr<
R?> onSuccess(- R data
- FutureOr<
R?> onFailure(- Object e,
- StackTrace s
- dynamic ignoreSkipError = true,
ignoreSkipError
same as update((o)=>null)
true: SkipError will not trigger onFailure
when true
ref skpIf/skpNull
Implementation
@visibleForTesting
@protected
FutureOr<R?> runCatching<R>(
FutureOr<R?> Function() block, {
FutureOr<R?> Function(R data)? onSuccess,
FutureOr<R?> Function(Object e, StackTrace s)? onFailure,
ignoreSkipError = true,
}) async {
try {
return switch (block()) {
Future<R> d => await d.then((e) => (onSuccess ?? (r) => r).call(e)),
Future<void> d => await d.then((e) => null),
R d => (onSuccess ?? (r) => r).call(d),
null => null,
};
} on SkipError catch (e, s) {
if (ignoreSkipError) return null;
return onFailure?.call(e, s);
} catch (e, s) {
return onFailure?.call(e, s);
}
}