invokeSafelyWith<T, A> static method
Future<T?>
invokeSafelyWith<T, A>(
- FutureOr<
T?> action(- A arg
- A arg, {
- void onError(
- dynamic ex
Invokes action, catching any exception it throws.
If onError is given, it is called with the exception;
otherwise the exception is silently ignored.
Implementation
static Future<T?> invokeSafelyWith<T, A>(
FutureOr<T?> Function(A arg) action, A arg,
{void onError(ex)?}) async {
try {
return await action(arg);
} catch (ex) {
onError?.call(ex);
}
}