whats this mean?

Sean 'Shaleh' Perry shalehperry at home.com
Fri Jul 20 22:41:15 EDT 2001


On 21-Jul-2001 TheDustbustr wrote:
># BEGIN CODE BLOCK
> try:
>     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>     s.bind((HOST, PORT))
>     s.listen(1)
>     conn, addr = s.accept()
> except socket.error, why: ## reference 1
>     print "Server Error: " + errno.errorcode[why[0]] + ", " + why[1] ##
> reference 2
>     sys.exit(1)
># END CODE BLOCK
> 
> what does reference 2 mean?  what do those brackets do?  And for reference 1,
> what will 'why' hold if an error occurs?
> 

>From the language reference, 4.2:
<quote>
When an exception is raised, an object (maybe None) is passed as the
exception's ``parameter'' or ``value''; this object does not affect the
selection of an exception handler, but is passed to the selected exception
handler as additional information. For class exceptions, this object must be an
instance of the exception class being raised. 

See also the description of the try statement in section 7.4 and raise
statement in section 6.8. 
</quote>

For fun, write an exception handler:

try:
        do something
except foo, e:
        print e
        print e[0], e[1], e[2]

Remember, the python interpreter can also be run interactively.  It is a great
way to experiment and learn.




More information about the Python-list mailing list