Exception handling....dumb question?
Flexx
flexx at jerasoft.net
Sun Apr 2 08:54:10 EDT 2006
Ben Finney writes:
> You should catch *specific* exceptions that you know you can deal with at that point in the code.
>
> import logging
> try:
> foo = 12 / 0
> except ZeroDivisionError, e:
> print "You *knew* this was going to happen: '%s'" % e
> logging.error(str(e))
>
> This allows all other exceptions to propogate back through the call
> stack.
import sys, logging
try:
foo = 12/0
except:
e = str(sys.exc_value)
print "You *knew* this was going to happen: '%s'" % (e)
logging.error(e)
More information about the Python-list
mailing list