guard<T> function

T guard<T>(
  1. T callback(
      ),
    1. [T defaultValue]
    )

    Evaluates the function 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

    T guard<T>(T Function() callback, [T defaultValue]) {
      T result;
    
      try {
        result = callback();
      } catch (err) {
        Vx.log(err);
      }
    
      return result ?? defaultValue;
    }