catchError method

FutureOr<T> catchError(
  1. Function onError, {
  2. bool test(
    1. Object error
    )?,
})

Catches errors in a Future or passes through non-Future values.

If this FutureOr is a Future, calls catchError on it. Otherwise, returns the value unchanged.

Parameters:

  • onError (Function, required): Error handler callback.
  • test (bool Function(Object)?, optional): Predicate to filter errors.

Returns: FutureOr<T> — the result with error handling applied.

Implementation

FutureOr<T> catchError(Function onError,
    {bool Function(Object error)? test}) {
  if (this is Future<T>) {
    return (this as Future<T>).catchError(onError, test: test);
  }
  return this;
}