Assuming you design a System.IO.Stream extension MyStream whose Read method can time out, which exception type would you rather throw:
System.IO.IOException (as e.g. System.Net.Sockets.NetworkStream) orSystem.TimeoutException (as e.g. System.IO.Ports.SerialPort) orIf the exception is that the Stream is going to "time out", then I would personally use TimeoutException. This is very clear, and very appropriate if that is the underlying cause.
IOException is used by NetworkStream, but has a different meaning. In this case, it's typically because the underlying socket has closed, which prevents the read/write from occurring...
You use a TimeoutException; it most accurately conveys what actually happened.
The IOException is more of a general-purpose exception; if something happened while reading the underlying backing store for the Stream for which there's not a specific exception then I'd expect an IOException.
TimeoutException is the standard here, so go with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With