Handlign exceptions - NEWBIE !!

Adrian Phillips (tandem@freeze.oslo.dnmi.no)
Mon, 14 Mar 1994 09:31:46 +0000

I'm completely new to python and need some help with how to handle errors
retruned from the socket module.

Can some kind person explain how to handle 'socket.error' using try/except.
Here is what I have done (plus various combinations):

s = socket (AF_INET, SOCK_STREAM)
while (1):
try:
s.bind (HOST, PORT)
except 'socket.error':
sys.stdout.write (socket.error[0] + socket.error[1])
continue
break
s.listen(5)

If the port is in use, the except condition seems to be ignored (presuambly
because I haven't done the except clause properly).

Any help would be greatly appreciated,

Thank you,

Adrian

-- 
---------------------
 ========================================================================
=   	    	    	    	    	    	    	    	    	 =
= Adrian Phillips at The Norwegian Meteorological Institute   	    	 =
=    	    	    	    	    	    	    	    	    	 =
= BUT any thoughts in this are purely my own and have nothing to do with =
= this establishment, thankfully.   	    	    	    	    	 =
=   	    	    	    	    	    	    	    	    	 =
= Internet: daap@typhoon.oslo.dnmi.no  	    	    	    	    	 =
= Phone: 47 22 96 32 09	    	    	    	    	    	    	 =
= Fax: 47 22 96 30 50	    	    	    	    	    	    	 =
=   	    	    	    	    	    	    	    	     	 =
 ========================================================================