当前位置:   article > 正文

python中的try能嵌套吗_更多的python方法来处理嵌套的try。。。除了街区?

python try catch exception还可以再加try吗

基于生成器的方法可能会比数据驱动方法提供更多的灵活性:def attempts_generator():

# try:

#

# except Exception as e:

# # failure

# yield e.message

# else:

# # success

# return

try:

print 'Attempt 1'

raise Exception('Failed attempt 1')

except Exception as e:

yield e.message

else:

return

try:

print 'Attempt 2'

# raise Exception('Failed attempt 2')

except Exception as e:

yield e.message

else:

return

try:

print 'Attempt 3'

raise Exception('Failed attempt 3')

except Exception as e:

yield e.message

else:

return

try:

print 'Attempt 4'

raise Exception('Failed attempt 4')

except Exception as e:

yield e.message

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/631423
推荐阅读
相关标签
  

闽ICP备14008679号