I am using a method that raises a KeyError. I would like to run that through a for loop and then display all these errors together at once when it's done with the loop. Is that possible ?
I am doing a Try except as this post indicates in order to ignore the KeyError(s).
bad_list = []
for i in range (10):
try:
bad_list.append(checkermethod(i)) #checker method raises TypeError when called
except KeyError:
continue
if bad_list:
raise KeyError('\n'.join(bad_list))
I am trying to catch these errors by appending a list, but it's always empty, so it's not really appending anything. This makes sense since I am actually ignoring the errors, but is there any idea on how to do that in another way?