Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1.45 KB

throw.md

File metadata and controls

45 lines (31 loc) · 1.45 KB

throw

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

Emit error on subscription.

Ultimate RxJS

Examples

Example 1: Throw error on subscription

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { throwError } from 'rxjs';

//emits an error with specified value on subscription
const source = throwError('This is an error!');
//output: 'Error: This is an error!'
const subscribe = source.subscribe({
  next: val => console.log(val),
  complete: () => console.log('Complete!'),
  error: val => console.log(`Error: ${val}`)
});

Related Examples

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/throwError.ts