asyncGuard<T> function
Evaluates the function asynchonically wrapping the body with try/catch and returns default value if error was raised or return value is null Originally available at https://pub.dev/packages/guard
Implementation
Future<T?> asyncGuard<T>(Future<T> Function() callback,
[T? defaultValue]) async {
T? result;
try {
result = await callback();
} catch (err) {
Vx.log(err.toString());
}
return result ?? defaultValue;
}