tryOr<T> function

T? tryOr<T>(
  1. T? defaultValue,
  2. T closure()
)

Returns the result of the given closure, or default if an Exception was raised.

Implementation

T? tryOr<T>(T? defaultValue, T Function() closure) {
  try {
    return closure();
  } on Exception {
    return defaultValue;
  }
}