ckass Bad(Exception):
pass
def test():
raise Bad(), "test bad"
try:
test()
except Bad, info:
print "bad", info
else:
print "else"
finally:
print "finally"
assert:
raise AssertionError when test evaluates to false
ex:
assert x<=3, 'x must be larger than 3'
raise:
ex1: raise object
class A:
pass
def test():
raise A()
ex2: raise string
message="Error"
def test():
raise message
沒有留言:
張貼留言