Catching an unknown error
skip at pobox.com
skip at pobox.com
Fri Mar 23 09:30:39 EDT 2007
Harlin> value = raw_input("Type a divisor: ")
Harlin> try:
Harlin> value = int(value)
Harlin> print "42 / %d = %d" % (value, 42/value)
Harlin> except ValueError:
Harlin> print "I can't convert the value to an integer"
Harlin> except ZeroDivisionError:
Harlin> print "Your value should not be zero"
Harlin> except:
Harlin> print "Something unexpected happened"
Harlin> In the last 'except' block, how can I print out the particular
Harlin> error name even though one is not specifically named?
>>> try:
... 1/0
... except Exception, err:
... print repr(err)
...
<exceptions.ZeroDivisionError instance at 0x81e96ac>
Skip
More information about the Python-list
mailing list