[英]How can I handle multiple same Error type in Python in try except block
I am trying to handle multiple same error in try except block. 我试图在try除了块之外处理多个相同的错误。 I have 2 function where I run 2nd function in except block if 1st block gives an error. 如果第一个块发出错误,我有2个函数,我在第二个函数中运行除了块。
I tried raising the exception like many post suggested and it didn't help. 我尝试像许多帖子一样提出异常,但没有帮助。 I am writing a simple code which in a way is similar running multiple function. 我正在编写一个简单的代码,在某种程度上类似于运行多个函数。 How can i try 10/0 if it fails try 20/0 in except and if we get error go to last except block? 我怎么能尝试10/0如果它失败尝试20/0 in除了如果我们得到错误去最后除了块?
try:
d =10/0
except ZeroDivisionError as e :
d=20/0
except ZeroDivisionError as f:
print("yes")
Result I am expecting according to my above code is "yes" since I get ZeroDivisionError twice. 结果我期待根据我的上面的代码是“是”因为我得到ZeroDivisionError两次。
You can chain try/except as follows. 您可以按如下方式链接try / except。
try:
d =10/0
except ZeroDivisionError as e :
try:
d=20/0
except ZeroDivisionError as f:
print("yes")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.