invokeSafelyWith<T, A> static method

Future<T?> invokeSafelyWith<T, A>(
  1. FutureOr<T?> action(
    1. A arg
    ),
  2. A arg, {
  3. void onError(
    1. 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);
  }
}