# -- coding: utf-8 -- #自定义异常 class myException(Exception): pass def division(x,y): if y == 1 : raise myException('y==1') #假如当y==1时,抛出自定义异常 return x/y try: division(1,0) except ZeroDivisionError as e: print(e) try: division(1,1) #抛出异常 except myException as e: print(e)
division by zero
y==1