handleError method

Stream<T> handleError (Function onError, { bool test(dynamic error) })

Creates a wrapper Stream that intercepts some errors from this stream.

If this stream sends an error that matches test, then it is intercepted by the onError function.

The onError callback must be of type void onError(error) or void onError(error, StackTrace stackTrace). Depending on the function type the stream either invokes onError with or without a stack trace. The stack trace argument might be null if the stream itself received an error without stack trace.

An asynchronous error error is matched by a test function if test(error) returns true. If test is omitted, every error is considered matching.

If the error is intercepted, the onError function can decide what to do with it. It can throw if it wants to raise a new (or the same) error, or simply return to make the stream forget the error. If the received error value is thrown again by the onError function, it acts like a rethrow and it is emitted along with its original stack trace, not the stack trace of the throw inside onError.

If you need to transform an error into a data event, use the more generic Stream.transform to handle the event by writing a data event to the output sink.

The returned stream is a broadcast stream if this stream is. If a broadcast stream is listened to more than once, each subscription will individually perform the test and handle the error.

Implementation

Stream<T> handleError(Function onError, {bool test(error)}) {
  return new _HandleErrorStream<T>(this, onError, test);
}