catchFuture<T> method

Future<T> catchFuture<T>(
  1. Future<T> task(), {
  2. bool catchError = true,
})

Implementation

Future<T> catchFuture<T>(Future<T> Function() task, {
  bool catchError = true,
}) async {
  try {
    addTask();
    final result = await task();
    return result;
  } catch (error, stacktrace) {
    if (catchError) {
      _errors.add(error);
    }
    if (kDebugMode) {
      stacktrace.printError();
    }
    throw error;
  } finally {
    completeTask();
  }
}