throw
签名: throw(error: any, scheduler: Scheduler): Observable
在订阅上发出错误
示例
示例 1: 在订阅上抛出错误
import { _throw } from 'rxjs/observable/throw';
// 在订阅上使用指定值来发出错误
const source = _throw('This is an error!');
// 输出: 'Error: This is an error!'
const subscribe = source.subscribe({
next: val => console.log(val),
complete: () => console.log('Complete!'),
error: val => console.log(`Error: ${val}`)
});
相关示例
其他资源
其他资源
- throw - 官方文档
- 创建操作符: empty, never 和 throw - André Staltz
源码:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/throwError.ts