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

  • Home
  • SEARCH
  • 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 6822983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:43:42+00:00 2026-05-26T21:43:42+00:00

The following code is pretty self-explanatory and my question is very simple : Why

  • 0

The following code is pretty self-explanatory and my question is very simple :
Why is AsyncCallback method “HandleConnect” not propagating exception to the “Connect” method
and how to propagate it ?

    public void Connect(IPEndPoint endpoint, IVfxIpcSession session)
    {
        try 
        {  
          ipcState.IpcSocket.BeginConnect(ipcState.IpcEndpoint, HandleConnect, ipcState);  
        }

        catch(Exception x) 
        { 
          ManageException(x.ToString()); //Never Caught, though "HandleConnect" blows a SocketException
        }
    }

    private void HandleConnect(IAsyncResult ar) 
    {
      // SocketException blows here, no propagation to method above is made. 
      // Initially there was a try/catch block that hided it and this is NOT GOOD AT ALL 
      // as I NEED TO KNOW when something goes wrong here.
       ipcState.IpcSocket.EndConnect(ar);  
    }

1 – I guess this is pretty normal behavior. But I would appreciate a comprehensive explanation of why is this happening this way and what happens exactly behind the hoods.

2 – Is there any (quick and simple) way to propagate the exception through my app ?

forewarning I know many dudes in here are very critical and I anticipate the comment “Why don’t you put the ManageException directly in the “HandleConnect” Method. Well, to make a long story short, let’s just say “I got my reasons” lol. I just posted a code sample here and I want to propagate this exception way further than that and do much more stuff than showed in other places in the “N-upper” code.

EDIT
As an aswer to a comment, I also tried this previously indeed, with no luck :

    private void HandleConnect(IAsyncResult ar) 
    {          
        try 
        {
          ipcState.IpcSocket.EndConnect(ar);  
        }

        catch(Exception x) 
        { 
          throw x; // Exception Blows here. It is NOT propagated.
        }
    }

My Solution :
I ended up putting an Event Handler to whom every concerned code logic subscribes.

This way the exception is not just swallowed down nor just blows, but a notification is broadcasted.

 public event EventHandler<MyEventArgs> EventDispatch;
 private void HandleConnect(IAsyncResult ar) 
    {          
        try 
        {
          ipcState.IpcSocket.EndConnect(ar);  
        }

        catch(Exception x) 
        {               
           if (EventDispatch!= null)
           {
               EventDispatch(this, args);
           }
        }
    }

  //Priorly, I push subscriptions like that : 

  tcpConnector.EventDispatch += tcpConnector_EventDispatch;

  public void tcpConnector_EventDispatch(object sender, VfxTcpConnectorEventArgs args)
  {
        //Notify third parties, manage exception, etc.
  }

This is a little bit crooked, but it works fine

  • 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-05-26T21:43:43+00:00Added an answer on May 26, 2026 at 9:43 pm

    When you use BeginConnect the connection is done asynchronously. You get the following chain of events:

    1. Connect “posts” a request to connect through BeginConnect.
    2. Connect method returns.
    3. The connection is done in the background.
    4. HandleConnect is called by the framework with the result of the connect.

    When you reach step number 4, Connect has already returned so that try-catch block isn’t active any more. This is the behavior you get when using asynchronous implementations.

    The only reason you would have an exception caught in Connect is if BeginConnect fails to initiate the background connection task. This could e.g. be if BeginConnect validates the supplied arguments before initiating the background operation and throws an exception if they are not correct.

    You can use the AppDomain.UnhandledException event to catch any unhandled exceptions in a central place. Once the exception reaches that level any form of recovery is probably hard to achieve, since the exception could be from anywhere. If you have a recovery method – catch the exception as close to the origin as possible. If you only log/inform the user – catching centrally in once place is often better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think the question itself is pretty self-explanatory. The code is given below -
The title is pretty self explanatory. the following code...: URL imageUrl = new URL(url);
The following code should be pretty self-evident. What I have made up so far
The question is pretty self-explanatory. I don't understand what the return is doing in
Title pretty much sums it up. The external style sheet has the following code:
I am pretty sure the following button-activated form code should raise a Control-F12 in
The following code works great in IE, but not in FF or Safari. I
Why would the following code throw this error? if ([self.tableView.dataSource numberOfSectionsInTableView:self.tableView] > 0 &&
I am learning this stuff so my code might not be pretty... but would
The following code produces pretty much what I want, but the scrollable pane on

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.