,System.Func{System.Exception,ReactiveUI.Extensions.Async.IObservableAsync{--0}})} ,System.Func{System.Exception,ReactiveUI.Extensions.Async.IObservableAsync{--0}},System.Func{System.Exception,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask})}
ObservableAsync.Catch(IObservableAsync, Func>) method¶
Defined in
Type: ObservableAsync
Namespace: ReactiveUI.Extensions.Async
Assembly: ReactiveUI.Extensions.dll
Applies to
net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481
Overloads¶
- 1.
public static IObservableAsync<T> Catch<T>(this IObservableAsync<T> source, Func<Exception, IObservableAsync<T>> handler) - 2.
public static IObservableAsync<T> Catch<T>(this IObservableAsync<T> source, Func<Exception, IObservableAsync<T>> handler, Func<Exception, CancellationToken, ValueTask>? onErrorResume)
1. Overload¶
public static IObservableAsync<T> Catch<T>(this IObservableAsync<T> source, Func<Exception, IObservableAsync<T>> handler)
Summary: Creates a new observable sequence that continues with a handler-provided sequence when an exception occurs in the source sequence.
Type parameters
| Name | Description |
|---|---|
T | The type of elements in the sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | [IObservableAsync | The source observable sequence. |
handler | Func | A function that receives the exception thrown by the source sequence and returns an alternative observable sequence to continue with. |
Returns: IObservableAsync
Remarks
Use this method to recover from errors in the source sequence by switching to an alternative observable sequence. The handler function is called with the exception, allowing custom error recovery logic. If the handler itself throws an exception, the resulting sequence completes with that exception.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown if the source sequence or handler is null. |
2. Overload¶
public static IObservableAsync<T> Catch<T>(this IObservableAsync<T> source, Func<Exception, IObservableAsync<T>> handler, Func<Exception, CancellationToken, ValueTask>? onErrorResume)
Summary: Creates a new observable sequence that continues with a handler-provided sequence when an exception occurs in the source sequence.
Type parameters
| Name | Description |
|---|---|
T | The type of elements in the sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | [IObservableAsync | The source observable sequence. |
handler | Func | A function that receives the exception thrown by the source sequence and returns an alternative observable sequence to continue with. |
onErrorResume | Func | An optional asynchronous callback invoked when an error occurs. If not specified, the observer's default error handler is used. |
Returns: IObservableAsync
Remarks
Use this method to recover from errors in the source sequence by switching to an alternative observable sequence. The handler function is called with the exception, allowing custom error recovery logic. If the handler itself throws an exception, the resulting sequence completes with that exception.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown if the source sequence or handler is null. |