python教程系列(三.4.4、自定义异常)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cui130/article/details/86408204

在这里插入图片描述

文章目录

class hexinException(BaseException):
    def __init__(self,msg):
        self.msg=msg
    def __str__(self):
        return self.msg

try:
    raise hexinException('类型错误')
except hexinException as e:
    print(e)

输出

类型错误

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/cui130/article/details/86408204