0

I have a block of C# code that contains a try/catch when connecting a client to a server using SignalR. My issue is that if I try to handle AggregateException using Microsoft's example here I end up with an infinite loop of AggregateException being thrown and caught even though I am thinking they shouldn't be.

My code looks just like Microsofts:

Connection = new HubConnection(Url);
Hub = Connection.CreateHubProxy(HubProxy);
try
{
    Connection.Start().Wait();
}
catch (AggregateException aggEx)
{
    foreach (var e in aggEx.InnerExceptions)
    {
        if (e is SocketException)
        {
            Console.WriteLine(e.ToString());
        }
        else
        {
            throw;
        }
    }
}

What would cause this to happen?

2

1 Answer 1

2

You are not cacthing the exception throwed in cacth block. Visual Studio's default behaviour is to stop at the place where an unhandled exception would terminate the application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.