码迷,mamicode.com
首页 > 其他好文 > 详细

自定义异常处理

时间:2019-02-14 00:20:55      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:self   init   cep   except   return   str   style   sage   bsp   

class MyExcept(Exception):
    def __init__(self, msg):
        self.message = msg

    def __str__(self):
        return self.message


try:
    raise MyExcept("我的异常")
except MyExcept as e:
    print(e)

 

自定义异常处理

标签:self   init   cep   except   return   str   style   sage   bsp   

原文地址:https://www.cnblogs.com/sunBinary/p/10372415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!