主动抛出异常
raise IOError('this is a test')
def get_age():
while True: #大小写敏感 True 不是 true
try:
n=int(raw_input('How Old You\n'))
return n
except ValueError:
print 'please input an integer value'
age=get_age()
print age+10
多种异常的捕获:
try:
...
except (ValueError,TypeError):
try:
...
except ValueError:
...
except TypeError:
...
所有异常的捕获:
try:
...
except:
...
完整的快:
try:
...
except:
...
finally:
...
raise IOError('this is a test')
def get_age():
while True: #大小写敏感 True 不是 true
try:
n=int(raw_input('How Old You\n'))
return n
except ValueError:
print 'please input an integer value'
age=get_age()
print age+10
多种异常的捕获:
try:
...
except (ValueError,TypeError):
try:
...
except ValueError:
...
except TypeError:
...
所有异常的捕获:
try:
...
except:
...
完整的快:
try:
...
except:
...
finally:
...