throw

签名: throw(error: any, scheduler: Scheduler): Observable

在订阅上发出错误

throw - 图1

示例

示例 1: 在订阅上抛出错误

( jsBin |
jsFiddle )

  1. import { _throw } from 'rxjs/observable/throw';
  2. // 在订阅上使用指定值来发出错误
  3. const source = _throw('This is an error!');
  4. // 输出: 'Error: This is an error!'
  5. const subscribe = source.subscribe({
  6. next: val => console.log(val),
  7. complete: () => console.log('Complete!'),
  8. error: val => console.log(`Error: ${val}`)
  9. });

相关示例

其他资源

其他资源

:file_folder: 源码:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/throwError.ts