exceptions again?

Ron Forrester (rjf@aurora.pcg.com)
Mon, 30 Jan 1995 13:09:25 -0700

Ok, I realize my original question on catching http/url lib exceptions was
pretty broad -- I spent all morning experimenting and trying to get closer to
a more specific question.

The first exception handler I coded was this:

try:
f = urllib.urlopen(url)
except IOError, (error, msg):
print error + ": " + msg
return

This worked great when the exception type thrown was a socket error (i.e.
('socket error', 'host not found')) or any one with only two members in the
tuple.

However, if I specify an unknown host, I get this message:

('http error', 404, 'Not Found', <Message instance at 3222ec>)

and an error saying that the tuple unpacked to the wrong size -- this makes
sense.

My question is, how do I code the except such that I can handle and correctly
identify each type of error appropriately?

Thanks!
rjf

-- 
| "I don't like being bluffed -- makes me doubt     |    rjf@aurora.pcg.com |
| my perception of reality..."                      |            71722,3175 |
|                      Chris in the morning on KBHR |                       |
+---------------------------------------------------+-----------------------+