An exception handler is used for exceptions thrown by the observer himself, and not by the observer.
An easy way to trigger an exception handler is something like this:
using System;
using System.Linq;
class Test
{
static void Main(string[] args)
{
var xs = Observable.Range(1, 10)
.Select(x => 10 / (5 - x));
xs.Subscribe(x => Console.WriteLine("Received {0}", x),
ex => Console.WriteLine("Bang! {0}", ex),
() => Console.WriteLine("Done"));
Console.WriteLine("App ending normally");
}
}
Conclusion:
Received 2
Received 3
Received 5
Received 10
Bang! System.DivideByZeroException: Attempted to divide by zero.
at Test.<Main>b__0(Int32 x)
at System.Linq.Observable.<>c__DisplayClass35a`2.<>c__DisplayClass35c.<Select
>b__359(TSource x)
App ending normally
source
share