星期三, 十月 04, 2006

python: raise a string for Exception?

>>> try:
... raise "a string"
... except str:
... print 'catch'
...
Traceback (most recent call last):
File "", line 2, in ?
a string

>>> try:
... raise "a string"
... except Exception, strerr:
... print "catch it"
...
Traceback (most recent call last):
File "", line 2, in ?
a string

>>> try:
... raise "a string"
... except "a string":
... print "catch it"
...
catch it

>>> ex = "a string"
>>> try:
... raise ex
... except ex, strerr:
... print "catch it: %s" % strerr
...
catch it: None

没有评论: