Python中的异常(多个try块)

时间:2017-10-10 09:52:21

标签: python python-3.x

我是python的新手,我一直想知道你是否可以在python中做这样的事情。

try:
   something():
if it throws an exception then try this:
   something1():
if it throws an exception again:
   print(exception)

1 个答案:

答案 0 :(得分:1)

当然可以。

try:
    something()
except Exception as exp:
    try:
        something1()
    except Exception as exp2:
        print(exp, exp2)
        raise exp # in case you want to raise the original exception