2024-06-10 02:25:35 发布
网友
我使用以下方法来处理Python中的Twilio异常:
try: #code for sending the sms print(message.sid) except TwilioRestException as e: print(e)
这允许我发送短消息,异常由Python处理
现在我需要“返回”异常代码来处理它们,比如,根据异常给用户一条消息
我怎样才能做到这一点
如果引发异常不是一个选项,您可以简单地在except块下添加return
def func(): # your logic try: #code for sending the sms print(message.sid) except TwilioRestException as e: print(e) return e.code # or whetever attribute e has for it...
默认情况下,如果一切正常,函数将返回None。在客户端代码中
None
err = func() if err: # sms wasn't sent, action required
如果引发异常不是一个选项,您可以简单地在except块下添加return
默认情况下,如果一切正常,函数将返回
None
。在客户端代码中相关问题 更多 >
编程相关推荐