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)

 代码如上所示:

原文地址:https://www.cnblogs.com/linwenbin/p/11815426.html