invokeSafely<T> static method
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?> invokeSafely<T>(FutureOr<T?> Function() action,
{void onError(ex)?}) async {
try {
return await action();
} catch (ex) {
onError?.call(ex);
}
}