gpt4 book ai didi

c# - IOException 与 TimeoutException

转载 作者:太空狗 更新时间:2023-10-29 23:25:44 27 4
gpt4 key购买 nike

假设您设计了一个 System.IO.Stream 扩展 MyStream,其 Read 方法可能会超时,您希望抛出哪种异常类型:

  • System.IO.IOException(例如 System.Net.Sockets.NetworkStream)或
  • System.TimeoutException(例如 System.IO.Ports.SerialPort)或
  • 还有别的吗?

最佳答案

如果异常是 Stream 将要“超时”,那么我个人会使用 TimeoutException。如果这是根本原因,这是非常明确和非常恰当的。

IOExceptionNetworkStream 使用,但具有不同的含义。在这种情况下,通常是因为底层套接字已关闭,从而阻止了读/写的发生...

关于c# - IOException 与 TimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8230909/

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