RxJS - 建立運算子 throwError



此運算子將建立一個可觀察物件,以通知錯誤。

語法

throwError(error: any): Observable

引數

錯誤 − 運算子獲取的引數是您需要通知的錯誤。

返回值

它返回一個可觀察物件,以通知錯誤。

示例

import { throwError, concat, of } from 'rxjs';

const result =throwError(new Error('error occurred'));
result.subscribe(x => console.log(x), e => console.error(e));

輸出

throwError Operator
廣告
© . All rights reserved.