如何在 modern Python 中声明自定义异常?
要在 Modern Python 中覆盖内容或向异常传递额外的参数,需要这样做
class ValidationError(Exception): def __init__(self, message, errors): super(ValidationError, self).__init__(message) self.errors = errors
通过这种方式,我们可向第二个参数传递错误消息的字典,并在需要时稍后获取。
广告
要在 Modern Python 中覆盖内容或向异常传递额外的参数,需要这样做
class ValidationError(Exception): def __init__(self, message, errors): super(ValidationError, self).__init__(message) self.errors = errors
通过这种方式,我们可向第二个参数传递错误消息的字典,并在需要时稍后获取。