【发布时间】:2019-09-17 07:00:05
【问题描述】:
我想知道在以下方法中使用 try/except 块的副作用或未知问题?
方法一:
def f1():
try:
# some code here
except Exception as e:
print(str(e))
def f2():
try:
f1()
except Exception as e:
print(str(e))
方法 2:与方法 1 中的逻辑相同,但在 f1() 中没有 try/block
def f1():
# some code here
def f2():
try:
f1()
except Exception as e:
print(str(e))
方法 3:使用多个嵌套函数
def f1():
# some code here
def f4():
# some code here
def f3():
f4()
# some code here
def f2():
try:
f1()
f3()
except Exception as e:
print(str(e))
方法 4:在每个函数中添加多个 try/except
def f1():
try:
# some code here
except Exception as e:
print(str(e))
def f4():
try:
# some code here
except Exception as e:
print(str(e))
def f3():
try:
f4()
# some code here
except Exception as e:
print(str(e))
def f2():
try:
f1()
f3()
except Exception as e:
print(str(e))
【问题讨论】:
-
根据定义,我们不知道。
标签: python try-except