class NewError(Exception):
    def __init__(self,message):
        self.msg = message
    def __str__(self):
        return self.msg

try:
    raise NewError('自定义新异常')
except NewError as e:
    print(e)

输出:

自定义新异常

posted on 2021-12-12 19:29  csy113  阅读(146)  评论(0编辑  收藏  举报