Learn RxJS
Search…
throw

signature: throw(error: any, scheduler: Scheduler): Observable

Emit error on subscription.

Examples

Example 1: Throw error on subscription
1
// RxJS v6+
2
import { throwError } from 'rxjs';
3
4
//emits an error with specified value on subscription
5
const source = throwError('This is an error!');
6
//output: 'Error: This is an error!'
7
const subscribe = source.subscribe({
8
next: val => console.log(val),
9
complete: () => console.log('Complete!'),
10
error: val => console.log(`Error: ${val}`)
11
});
Copied!

Additional Resources

Last modified 1yr ago