如何在Python中重用多个函数的异常处理代码?
我正在开发一个将使用Stripe Python库的项目. https://stripe.com/docs/api/python#errors
这是他们的文档中的一些示例代码.
try:
# Use Stripe's bindings...
pass
except stripe.error.CardError, e:
# Since it's a decline, stripe.error.CardError will be caught
body = e.json_body
err = body['error']
print "Status is: %s" % e.http_status
print "Type is: %s" % err['type']
print "Code is: %s" % err['code']
# param is '' in this case
print "Param is: %s" % err['param']
print "Message is: %s" % err['message']
except stripe.error.InvalidRequestError, e:
# Invalid parameters were supplied to Stripe's API
pass
except stripe.error.AuthenticationError, …Run Code Online (Sandbox Code Playgroud)