Finn,

 

Thanks for this.

I thought since I wasn't actually using the socket module I wouldn't have to use withSocketsDo.

The documentation for BSD is a little spartan and a few explanatory words about how errors get handled wouldn't go amiss.

Anyway, it now works so I'll move on to the next bit.

Dominic.

Finn Wilcox <[EMAIL PROTECTED]>
03/03/2002 09:30
Please respond to finnw

To: [EMAIL PROTECTED]
cc: [EMAIL PROTECTED]
bcc:
Subject: Re: getProtocolByName


On Sun, 3 Mar 2002 [EMAIL PROTECTED] wrote:

> Here's my test program. TCP is a valid protocol. But I get the following
> when I run it. I'm running under W98 by the way. I have two questions:
>
> 1) Why do I get an error?

You want:
> module Main(main) where
>
> import BSD
 import Socket (withSocketsDo)
>
> main =
    withSocketsDo $
>    do protocolEntry <- getProtocolByName "TCP"
    ...
>
See http://www.haskell.org/ghc/docs/latest/set/socket.html#AEN14601

> 2) Even if this is a valid error why doesn't the function tell me so that I
> can handle it rather than terminating?
>
It is a valid error.  It is raising an exception which you can catch if you
want. e.g.

import IO (catch, isDoesNotExistError)
...
  catch (do protocolEntry <- getProtocolByName "TCP"
            putStrLn ("Protocol name:" ++ (protoName protocolEntry)))
        (\e -> if isDoesNotExistError e then
                  putStrLn "Error" else
                  ioError e)

Finn.

_______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

Reply via email to