python 自定义错误处理

Posted 每天增长一点点

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 自定义错误处理相关的知识,希望对你有一定的参考价值。

简单的自定义异常处理

class CustomizeError(BaseException):
    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return self.msg

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

 

以上是关于python 自定义错误处理的主要内容,如果未能解决你的问题,请参考以下文章