我有一个套接字,我想发送消息并从中读取。
当我在另一端离线时使用套接字进行读/写时,我得到了相同的异常:System.IO.IOException: Unable to read data from the transport connection: Operation on non-blocking socket would block
。
除了有两个单独的try-catch块之外,我如何识别这两个块中的哪一个发生了这种情况?当读取超时结束时,我就不能得到一个Timeout Exception
吗?
示例:
try
{
SendData("!GetLocation!");
string data = GetData();
}
catch (Exception ex)
{
if (ex is System.IO.IOException)
{
//How can I identify if the exception was raised at the read method or the write method?
}
}
https://stackoverflow.com/questions/56118266
复制相似问题