自定义异常的两种方式

try:
   a=2;b=1
   if a>b:
       raise Exception("dayu")
except Exception as ff:
   print (ff)

————————————————————————————
class ownerException(Exception):
    def __init__(self,message):
        self.message=message
try:
   a=2;b=1
   if a>b:
       raise ownerException("dayu!!!")
except ownerException as gg:
   print (gg.message)

  

猜你喜欢

转载自www.cnblogs.com/qinyios/p/10016367.html