首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何区别于编写异常和读取异常?

如何区别于编写异常和读取异常?
EN

Stack Overflow用户
提问于 2019-05-14 02:49:26
回答 1查看 49关注 0票数 0

我有一个套接字,我想发送消息并从中读取。

当我在另一端离线时使用套接字进行读/写时,我得到了相同的异常: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?
        }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56118266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档