我想知道是否有可能将异常捕获到列表中(存储错误),继续执行for item in list
,直到所有项目都被迭代为止,然后对错误进行排序并打印唯一的错误?有关异常处理的建议
希望这是有道理的。这里是一个功能的一个简单的例子,试图说明我的意思:
def function1(list1, list2)
for item in list1:
for item in list2:
try:
do stuff here #iterates both lists
except:
capture exception append to list
errors = sort(exceptions)
print unique exceptions
打印异常时,“独一无二”是什么意思? – martineau