python自定义异常

class ShortInputException(Exception):
    def __init__(self, msg):
        self.msg = msg
 
    def __str__(self):
        return str(self.msg)
    
 
try:
    print('zz')
    raise ShortInputException('短了。。。')
except Exception as e:
    print(e)

 代码如上所示:

posted @ 2019-11-07 20:37  志不坚者智不达  阅读(111)  评论(0编辑  收藏  举报