1# Python List Comprehension Error Handling:
2# The correct responses to the question "how to handle exceptions in a list
3# comprehension" are all expressing part of all of this truth: 1) literally,
4# i.e. lexically IN the comprehension itself, you can't; 2) practically, you
5# delegate the job to a function or check for error prone values when that's
6# feasible.
1def catch(func, *args, handle=lambda e : None, **kwargs):
2 try:
3 return func(*args, **kwargs)
4 except Exception as e:
5 return handle(e)
6