ReferencethrowError
Reference · 08
throwError
throwError
An Observable that emits an error immediately.
Signature
throwError(errorFactory: () => any): Observable
Marble diagram
throwError(...): (#)
What it does
On each subscription it calls the error factory and sends the error via error. The factory ensures the stack trace is tied to the subscription site, not the Observable's creation site. The old form throwError(err) (without a factory) is deprecated.
When to use
In tests, simulating network failures. In catchError chains, converting one error into another (throwError(() => new MyAppError(...))). In switchMap, rejecting invalid inputs.
See also
catchError, retry, EMPTY
script.ts
CONSOLE · Console output
Hit Run to see the result...