catching<T> static method

Future<ResourceTry<T>> catching<T>(
  1. Future<T> closure()
)

Implementation

static Future<ResourceTry<T>> catching<T>(Future<T> Function() closure) =>
    closure().then((value) => ResourceTry.success(value)).catchError((e, st) {
      if (e is FileNotFoundException) {
        return ResourceTry<T>.failure(ResourceException.notFound);
      }
      if (e is Exception) {
        return ResourceTry<T>.failure(ResourceException.wrap(e));
      }
      if (e is OutOfMemoryError) {
        // We don't want to catch any Error, only OOM.
        return ResourceTry<T>.failure(ResourceException.wrap(e));
      }
    });