Note that there are some explanatory texts on larger screens.

plurals
  1. POCatching exceptions which may be thrown from a Subscription OnNext Action
    primarykey
    data
    text
    <p>I'm somewhat new to Rx.NET. Is it possible to catch an exception which may be thrown by any of the subscribers? Take the following...</p> <pre><code>handler.FooStream.Subscribe( _ =&gt; throw new Exception("Bar"), _ =&gt; { }); </code></pre> <p>Currently I'm catching on a per subscription basis with an instance of the following. The implementation of which just uses a ManualResetEvent to wake up a waiting thread.</p> <pre><code>public interface IExceptionCatcher { Action&lt;T&gt; Exec&lt;T&gt;(Action&lt;T&gt; action); } </code></pre> <p>and using it like so...</p> <pre><code>handler.FooStream.Subscribe( _exceptionCatcher.Exec&lt;Foo&gt;(_ =&gt; throw new Exception("Bar")), //It's disappointing that this generic type can't be inferred _ =&gt; { }); </code></pre> <p>I feel like there must be some better way. Are all of the error handling capabilities in Rx.NET specifically for dealing with errors observables?</p> <p>EDIT: Per request, my implementation is <a href="https://gist.github.com/1409829" rel="noreferrer">https://gist.github.com/1409829</a> (interface and implementation separated into different assemblies in prod code). Feedback is welcome. This may seem silly, but I'm using castle windsor to manage many different Rx subscribers. This exception catcher is registered with the container like this</p> <pre><code>windsorContainer.Register(Component.For&lt;IExceptionCatcher&gt;().Instance(catcher)); </code></pre> <p>It would then be used like this where <code>observable</code> is instance of IObservable:</p> <pre><code>var exceptionCatcher = new ExceptionCatcher(e =&gt; { Logger.FatalException( "Exception caught, shutting down.", e); // Deal with unmanaged resources here }, false); /* * Normally the code below exists in some class managed by an IoC container. * 'catcher' would be provided by the container. */ observable /* do some filtering, selecting, grouping etc */ .SubscribeWithExceptionCatching(processItems, catcher); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload