ObservableForProperty(...).Subscribe(_ => Something()) eats exceptions?

373 views
Skip to first unread message

Charles Josephs

unread,
May 19, 2013, 11:29:57 AM5/19/13
to reacti...@googlegroups.com
ObservableForProperty(...).Subscribe(_ => Something());

In the code snippet above if the Something() method throws an exception, it is silently eatten.

ObservableForProperty(...).Subscribe(_ => Something(), e => HandleException(e));

Even if I attempt to handle the exception reactively. HandleException is never called. 

I'm relatively new to ReactiveUI and Reactive itself so I may just be missing something obvious. Any ideas?

Paul Betts

unread,
May 20, 2013, 12:00:04 PM5/20/13
to ReactiveUI mailing list
Hi Charles,

This isn't how Rx works, it makes no guarantees about what happens in the OnNext of the subscribe. If you did something like this:

ObservableForProperty(...).Select(_ => Something().Subscribe(_ => {}, e => HandleException(e));

Then you'd see it show up. Also, ObservableForProperty is mostly deprecated by WhenAny, use that instead :)


--
You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivexaml...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Charles Josephs

unread,
May 22, 2013, 1:04:04 PM5/22/13
to reacti...@googlegroups.com
Ahh I see. I believe I understand why it is the way it is and how your code addresses the situation. My needs were slightly different, however. I needed Something() to be able to throw an exception without breaking the observable -- or to be more accurate, I was in a situation where I was trying use exceptions to control flow. My final solution was to address that design flaw in my code. Thanks, btw, for the heads up with WhenAny :)

Paul Betts

unread,
May 22, 2013, 2:31:53 PM5/22/13
to reacti...@googlegroups.com
The one pattern where breaking the Observable *is* common / useful is in
ReactiveAsyncCommand:

var cmd = new ReactiveAsyncCommand();

cmd.RegisterAsyncObservable(_ => Observable.Throw<int>(new Exception("Oh noes!")))
.ToProperty(this, x => x.SomeInt);

cmd.ThrownExceptions.Subscribe(ex => Console.WriteLine(ex));

Since the thing you pass to RegisterAsyncObservable is a factory method, it
will create a new Observable every time.

--
Paul Betts <pa...@paulbetts.org>

On Wed, May 22, 2013 at 10:04:04AM -0700, Charles Josephs wrote:
> Ahh I see. I believe I understand why it is the way it is and how your code
> addresses the situation. My needs were slightly different, however. I
> needed Something() to be able to throw an exception without breaking the
> observable -- or to be more accurate, I was in a situation where I was
> trying use exceptions to control flow. My final solution was to address
> that design flaw in my code. Thanks, btw, for the heads up with WhenAny :)
>
> On Monday, May 20, 2013 12:00:04 PM UTC-4, Paul Betts wrote:
> >
> > Hi Charles,
> >
> > This isn't how Rx works, it makes no guarantees about what happens in the
> > OnNext of the subscribe. If you did something like this:
> >
> > ObservableForProperty(...).Select(_ => Something().Subscribe(_ => {}, e =>
> > HandleException(e));
> >
> > Then you'd see it show up. Also, ObservableForProperty is mostly
> > deprecated by WhenAny, use that instead :)
> >
> >
> > On Sun, May 19, 2013 at 11:29 AM, Charles Josephs <cjos...@gmail.com<javascript:>
> > > wrote:
> >
> >> ObservableForProperty(...).Subscribe(_ => Something());
> >>
> >>
> >> In the code snippet above if the Something() method throws an exception,
> >> it is silently eatten.
> >>
> >> ObservableForProperty(...).Subscribe(_ => Something(), e =>
> >>> HandleException(e));
> >>
> >>
> >> Even if I attempt to handle the exception reactively. HandleException is
> >> never called.
> >>
> >> I'm relatively new to ReactiveUI and Reactive itself so I may just be
> >> missing something obvious. Any ideas?
> >>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "ReactiveUI mailing list" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to reactivexaml...@googlegroups.com <javascript:>.
Reply all
Reply to author
Forward
0 new messages