Reputation: 2001
Note: I'm referring to the .NET 4 version of RX.
I've been using the ReplaySubject class of RX. I'm calling the OnError with an exception as the parameter.
I was expecting that it will notify all the OnError subscribers and will pass them the exception, instead it just throws the exception and after that the exception just go unhandled.
Code is very simple, you can have a look at the code on GitHub. https://github.com/arielbh/CodeCommander/blob/master/CodeValue.CodeCommander/CommandBase.cs Line 117 is the OnNext call.
Got any ideas? obviously I want the behavior I'm expecting to happen. Thanks
Ariel
Upvotes: 3
Views: 541
Reputation: 412
I hit this strange behavior too. I created my own extension method to get the behavior I was expecting.
public static void SendOnError<T, E>(this IObserver<T> Subject, E ExceptionToSend) where E : Exception
{
try { Subject?.OnError(ExceptionToSend); }
catch (E exception)
{
Debug.WriteLine("One or more subscribers to the subject did not implement an OnError handler. Ignoring rethrown exception: " + exception.Message);
}
}
Upvotes: 0
Reputation: 2001
OK, I found out the cause of it. If you are not subscribed to OnError, than the default behavior is throwing the exception. I was not careful enough so the Subject that raises the error was no being observed.
More info: http://social.msdn.microsoft.com/Forums/en/rx/thread/3125094b-1ab2-4d01-8f44-fb68ef913f43
Upvotes: 1