Future.error(Object error, [ StackTrace stackTrace ])

A future that completes with an error in the next event-loop iteration.

If error is null, it is replaced by a NullThrownError.

Use Completer to create a future and complete it later.

Source

factory Future.error(Object error, [StackTrace stackTrace]) {
  error = _nonNullError(error);
  if (!identical(Zone.current, _ROOT_ZONE)) {
    AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
    if (replacement != null) {
      error = _nonNullError(replacement.error);
      stackTrace = replacement.stackTrace;
    }
  }
  return new _Future<T>.immediateError(error, stackTrace);
}