>>> a = 5 # a is an integer
>>> b = "Bingo" # b is a string
>>>
>>> def add_five():
try:
c + 5 # c is not defined. NameError exception is raised
except NameError:
b + 5 # b is a string. TypeError exception is raised
except TypeError:
a + 5 # a is int. No exception is raised
except:
# This last except clause is just in case you forgot to handle any exception
pass
>>>
我认为你应该一个一个地处理每一个异常。这将缩短您的代码。首先注意
ftp.close()
和其他方法将引发的所有异常。然后逐一处理。你知道吗示例:
相关问题 更多 >
编程相关推荐