getProtocolByName
Dominic Steinitz
dominic.j.steinitz@britishairways.com
Sun, 3 Mar 2002 17:42:56 +0000
<P> Finn,</P><P> </P><P>Thanks for this. </P><P>I thought since I=
wasn't actually using the socket module I wouldn't have to use withSockets=
Do.</P><P>The documentation for BSD is a little spartan and a few explanato=
ry words about how errors get handled wouldn't go amiss.</P><P>Anyway, it n=
ow works so I'll move on to the next bit.</P><P>Dominic.<BR><BR><FONT SIZE=
=3D2><B>Finn Wilcox <finnw@sucs.org></B></FONT><BR><FONT SIZE=3D2>03/=
03/2002 09:30</FONT><BR><FONT SIZE=3D2>Please respond to finnw</FONT><BR><B=
R> <FONT SIZE=3D2>To:</FONT> <FONT SIZE=3D2>dominic.j.steinitz@britishairwa=
ys.com</FONT><BR> <FONT SIZE=3D2>cc:</FONT> <FONT SIZE=3D2>haskell@haskell.=
org</FONT><BR> <FONT SIZE=3D2>bcc:</FONT> <BR> <FONT SIZE=3D2>Subject:</FON=
T> <FONT SIZE=3D2>Re: getProtocolByName</FONT><BR> <BR><BR></P><P><FONT FAC=
E=3D"Monospace,Courier">On Sun, 3 Mar 2002 dominic.j.steinitz@britishairway=
s.com wrote:<BR></FONT><BR><FONT FACE=3D"Monospace,Courier">> Here's my =
test program. TCP is a valid protocol. But I get the following<BR>> when=
I run it. I'm running under W98 by the way. I have two questions:<BR>><=
BR>> 1) Why do I get an error?<BR></FONT><BR><FONT FACE=3D"Monospace,Cou=
rier">You want:<BR>> module Main(main) where<BR>><BR>> import BSD<=
BR> import Socket (withSocketsDo)<BR>><BR>> main =3D<BR> =
withSocketsDo $<BR>> do protocolEntry <- getProt=
ocolByName "TCP"<BR> ...<BR>><BR>See <A HREF=3Dh=
ttp://www.haskell.org/ghc/docs/latest/set/socket.html#AEN14601>http://www.h=
askell.org/ghc/docs/latest/set/socket.html#AEN14601</A><BR></FONT><BR><FONT=
FACE=3D"Monospace,Courier">> 2) Even if this is a valid error why doesn=
't the function tell me so that I<BR>> can handle it rather than termina=
ting?<BR>><BR>It is a valid error. It is raising an exception whic=
h you can catch if you<BR>want. e.g.<BR></FONT><BR><FONT FACE=3D"Monospace,=
Courier">import IO (catch, isDoesNotExistError)<BR>...<BR> catch (do=
protocolEntry <- getProtocolByName "TCP"<BR> &n=
bsp; putStrLn ("Protocol name:" ++ (protoNam=
e protocolEntry)))<BR> (\e -> if isDoesNotEx=
istError e then<BR> =
putStrLn "Error" else<BR> &nb=
sp; ioError e)<BR></FONT><BR><FONT FACE=3D"Mono=
space,Courier">Finn.</FONT></P>=