python自定义异常处理_Python自定义异常处理

在古力苦苦寻找到底发生了什么之后,这是:

我有一个自定义验证异常,它接受请求和响应class ValidationException(Exception):

message = "Caught Validation Exception"

def __init__(self, request, response):

self.details = {

"request": request,

"response": response

}

super(ValidationException, self).__init__(self.message, self.details)

我有一个异常处理程序,它将在某些情况下引发它的实例:

^{pr2}$

处理程序在post中遇到问题时被调用class Poster:

def post(data):

if self.last_response.status_code not in self.valid_post_codes:

self.exception_handler.handleException(self.last_request, self.last_response)

问题是,我提出了ValidationException,在我的回溯中得到了它,但是,它似乎没有在我想要的地方被发现。在def testThis(self):

try:

self.poster.post(json.dumps({}))

except ValidationException:

print "got validation"

except Exception:

print "got exception"

结果:“获得异常”

回溯lib/service/pas/api/order.py line 24 in postOrder

return self.post()

lib/service/base.py line 42 in post

self.exception_handler.handleException(self.last_request, self.last_response)

lib/service/exception/handler.py line 14 in handleException

raise ValidationException(request, response)

ValidationException:

为了它的价值:assertRaises(ValidationException, self.poster.post, json.dumps({}))

也只捕获异常。有什么想法吗?:\n如有任何帮助,我们将不胜感激!提前谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值