自定义异常的两种方式

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)

  

posted @ 2018-11-25 17:24  黑魔法os  阅读(411)  评论(0编辑  收藏  举报