The following example is very simple. I want to execute map () with a function that can throw an exception. This will be more clear with an example:
number_list = range(-2,8) def one_divide_by(n): return 1/n try: for number, divide in zip(number_list, map(one_divide_by, number_list)): print("%d : %f" % (number, divide)) except ZeroDivisionError:
When I execute this code, I get:
-2 : -0.500000 -1 : -1.000000
This is because of 0 on my list. I do not want to remove this 0 (because in the real case, I cannot know first if I get an Exception). Do you know how to continue displaying after an exception ?
source share