0

I have two observables:

  1. Total process timeout (Observable 1)
  2. Current action timeout (Observable 2)

The second one makes use of the timeout extension method. The only thing I want to do is to throw my own exception instead of the default timeout exception.

var totalTimeout = Observable.Throw<FoobarException>(new FoobarException("my own text")).DelaySubscription(TimeSpan.FromSeconds(10));
var processStepTimeout = Observable.FromEventPattern(btn_nextStep, nameof(btn_nextStep.Click)).Timeout(TimeSpan.FromSeconds(3)); //my message
totalTimeout.Amb(processStepTimeout).Subscribe(ex => {}, ex => MessageBox.Show(ex.Message));
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
Uli
  • 9
  • 2

1 Answers1

0

You could use the Catch operator:

Continues an observable sequence that is terminated by an exception of the specified type with the observable sequence produced by the handler.

public static IObservable<TSource> Catch<TSource, TException>(
    this IObservable<TSource> source,
    Func<TException, IObservable<TSource>> handler) where TException : Exception;

Catch the TimeoutException and then throw your custom exception instead, using the Throw operator.

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104