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?

user2357446
  • 656
  • 6
  • 25
  • 2
    Are you sure it's an infinite loop? Maybe you're debugging and there's nowhere that catches the rethrow. [This answer has details.](http://stackoverflow.com/a/24962377) – 31eee384 Aug 25 '15 at 14:06
  • possible duplicate of [C# - Infinite Loop at Exception Throwing?](http://stackoverflow.com/questions/24961208/c-sharp-infinite-loop-at-exception-throwing) – Artiom Aug 25 '15 at 14:08

1 Answers1

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.

onatm
  • 816
  • 1
  • 11
  • 29