On Fri, 11 Mar 2011, Daniel Fischer wrote:
On Friday 11 March 2011 17:04:16, Daniel Díaz wrote:
Hi, cafe,
I'm working in a program where I use many connections with Network.HTTP. Sometimes, connections are closed while my program is reading them, and an error appears:
<socket: XXX>: Data.ByteString.hGetLine: invalid argument (Bad file descriptor)
All I need is to handle this error. The function 'catch' doesn't work. I guess this error comes from a call to 'error' function, or something similar.
Control.Exception.catch can catch error calls. If you're using Prelude.catch, you probably should switch.
Using 'error' in such cases would be definitely wrong, since a connection closed by the other end of the connection is not a programming error but an exceptional situation that we must handle properly at runtime. Unfortunately it is not documented in bytestring package, what exceptions hGetLine can throw and the type IO does not tell us, too. (For alternatives see: http://www.haskell.org/pipermail/haskell-cafe/2011-March/089936.html) You may scan the exceptions in http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Control-Ex... for types that may be responsible for invalid file descriptors. This should certainly be in IOException, but on the other hand, IOException is also what Prelude.catch catches.