Visual Studio Breaks on Exceptions for Async Calls Instead of Being Caught in Catch()

2

I have the following code that is trying to catch the exception caused by a disconnect:

try
{
    DataReaderLoadOperation op = dataReader.LoadAsync((uint)readBuffer.MaxLength());
    await op;  //  <-- Debugger show COMException here
    ReceiveCallback(op, op.Status);
}
catch (COMException e)
{
    Logger.Info("{0} disconnected. (Waiting)", this);
    Logger.Debug("{0} exception = {1}", this, e);
    OnDisconnected();
}

Why does my code not catch it? Here is the dump of the exception:

System.Runtime.InteropServices.COMException occurred   
  HResult=-2147014842   
  Message=An existing connection was forcibly closed by the remote host. (Exception from HRESULT: 0x80072746)   
  Source=mscorlib   
  ErrorCode=-2147014842   
  StackTrace:
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Crystal.IO.Network.SocketClient.<WaitForIncoming>d__4.MoveNext() in d:\Crystal\library\IO\Network\SocketClient.cs:line 479   
  InnerException:
c#
exception
asynchronous
windows-8
windows-runtime
asked on Stack Overflow May 6, 2012 by Nick Banks • edited Dec 3, 2013 by Chris Moschini

1 Answer

2

Change your debugger settings to not break on first chance exceptions.

answered on Stack Overflow May 6, 2012 by GETah

User contributions licensed under CC BY-SA 3.0