wrap<T> static method

FutureOr<ErrorOr<T>> wrap<T>(
  1. FutureOr<T> throwing()
)

Wrap a throwing function in a try/catch and return an ErrorOr with either a value or an error, based on whether an exception was thrown or not.

Implementation

static FutureOr<ErrorOr<T>> wrap<T>(FutureOr<T> Function() throwing) async {
  try {
    return ErrorOr.value(await throwing());
  } catch (e) {
    return ErrorOr.error(e);
  }
}