Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8866695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:51:27+00:00 2026-06-14T16:51:27+00:00

I’m using the reactive extensions for a kind of a in process message bus.

  • 0

I’m using the reactive extensions for a kind of a in process message bus.
The implementation is quite simple.

Register looks like

public IDisposable Register<T>(Action<T> action) where T : IMessage
{
   return this.subject
        .OfType<T>()
        .Subscribe(action);
}

And send simply:

private void SendMessage(IMessage message)
    {
        this.subject.OnNext(message);
    }

However i’m now having some trouble with the exception behaviour of RX.
One an exception is thrown in a registered/subscribed action – the Observable ‘stream’ is broken and will not subscribe anymore.
Sine this message bus is used for two parts of the application to communicate i need to ensure that such a stream is never broken even if an unexpected exception is thrown.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:51:28+00:00Added an answer on June 14, 2026 at 4:51 pm

    If you need to ensure that the stream is never broken by an exception, then you need to have another channel for the exceptions.

    This behavior is not completely unexpected. From the documentation for the IObserver<T> interface:

    The OnError method, which is typically called by the provider to indicate that data is unavailable, inaccessible, or corrupted, or that the provider has experienced some other error condition.

    Given this, if the stream is unavailable, corrupted, etc, you definitely want the stream to be “faulted” (this is analagous to a channel being faulted in WCF); the state is indeterminate so you can’t rely on anything else that comes from the IObservable<T> implementation; so why should there be an expectation that there will be any more observations?

    That said, you have a some options:

    Swallow the exception

    You’d have to wrap the action delegate that you pass into your Register function, like so:

    public IDisposable Register<T>(Action<T> action) where T : IMessage
    {
       return this.subject
            .OfType<T>()
            .Subscribe(t => {
                // Execute action
                try { action(t); }
                catch { }
             });
    }
    

    This, of course, might not be desirable, as you might be throwing away exceptions which impact your program (or, you might know exactly what’s going on here, and want to skip them), but it can be used to build on the next solution.

    Provide an action to take when an exception is thrown

    Using the above as the base, you can ask for an Action<T, Exception> which will be called when an exception is thrown.

    public IDisposable Register<T>(Action<T> action, 
        Action<T, Exception> errorHandler) where T : IMessage
    {
       return this.subject
            .OfType<T>()
            .Subscribe(t => {
                // Execute action
                try { action(t); }
                catch (Exception e) { errorHandler(t, e); }
             });
    }
    

    Now, when an exception is thrown from action, it will be passed to your exception handler without breaking the stream.

    The above can easily be overloaded to provide the behavior which will swallow the exception (which again, may or may not serve your purposes):

    public IDisposable Register<T>(Action<T> action) where T : IMessage
    {
        // Call the overload, don't do anything on
        // exception.
        return Register(action, (t, e) => { });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.