gpt4 book ai didi

c# - Visual Studio 中断异步调用的异常,而不是被捕获在 Catch() 中

转载 作者:太空宇宙 更新时间:2023-11-03 11:22:34 25 4
gpt4 key购买 nike

我有以下代码试图捕获由断开连接引起的异常:

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();
}

为什么我的代码没有捕捉到它?这是异常的转储:

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# - Visual Studio 中断异步调用的异常,而不是被捕获在 Catch() 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10474367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com