Skip to content

,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)

View source

Summary: Creates a new observable sequence that continues with a handler-provided sequence when an exception occurs in the source sequence.

Type parameters

NameDescription
TThe type of elements in the sequence.

Parameters

NameTypeDescription
source[IObservableAsync](#The source observable sequence.
handlerFunc>A function that receives the exception thrown by the source sequence and returns an alternative observable sequence to continue with.

Returns: IObservableAsync -- An observable sequence that emits items from the source sequence, or from the handler-provided sequence if an exception is encountered.

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

TypeCondition
System.ArgumentNullExceptionThrown 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)

View source

Summary: Creates a new observable sequence that continues with a handler-provided sequence when an exception occurs in the source sequence.

Type parameters

NameDescription
TThe type of elements in the sequence.

Parameters

NameTypeDescription
source[IObservableAsync](#The source observable sequence.
handlerFunc>A function that receives the exception thrown by the source sequence and returns an alternative observable sequence to continue with.
onErrorResumeFunc?An optional asynchronous callback invoked when an error occurs. If not specified, the observer's default error handler is used.

Returns: IObservableAsync -- An observable sequence that emits items from the source sequence, or from the handler-provided sequence if an exception is encountered.

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

TypeCondition
System.ArgumentNullExceptionThrown if the source sequence or handler is null.