3
votes

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

2
Sorry, I answered but then saw that you are refering to the .NET version and not the JavaScript Version which makes my answer useless. That's why I deleted my answer. - Christoph
Thanks and Sorry. I will make this more clear. - ArielBH

2 Answers

1
votes

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

0
votes

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);
        }
    }