1
我是新来的蟒蛇,我一直想知道如果你可以在Python中做这样的事情。在Python中的例外(多个尝试块)
try:
something():
if it throws an exception then try this:
something1():
if it throws an exception again:
print(exception)
我是新来的蟒蛇,我一直想知道如果你可以在Python中做这样的事情。在Python中的例外(多个尝试块)
try:
something():
if it throws an exception then try this:
something1():
if it throws an exception again:
print(exception)
当然可以。
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
你可以在另一个'try'块或者'except'块中放一个'try'块。 – khelwood