python异常处理

#coding:utf-8
__author__ = 'hdfs'
try:
name=['9','7']
name[3]
1/0
except IndexError,e:
print(e)
except Exception,e:
print(e)
finally:
print('End...>>>')

class MyException(Exception):
'''
自己的异常
'''
def __init__(self,err):
print('ni ge cuowu'+err)
try:
a=0
if a==0:
'''手动抛出一个异常'''
raise MyException(str(a))
except MyException,e:
print(e)
posted @ 2016-05-29 10:31  similarface  阅读(155)  评论(0编辑  收藏  举报