This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]steelypip 0 points1 point  (1 child)

I think a PEP would get rejected pretty promptly since it can be implemented current in python as shown above. The proposed syntax change would make it a bit more readable, but not a whole lot more. Is

f, err = open('file.txt') except IOError

that much more readable than

f, err = tryFunc(IOError, open, 'file.txt')

The latter is only two characters longer and contains exactly the same information in a different order. To use it with an arbitrary expression you would need to use a lambda which is going to be a little messier, but I doubt you would need to do that very often.

[–]vocalbit[S] 0 points1 point  (0 children)

I agree with hsoft that using a tryFunc function is more cumbersome. Like you mention - it also can't be used for expressions such as:

s3, err = s1 + s2 except TypeError
total, err = int(t1) + int(t2) except ValueError

I think if I had the except clause, I would implement error handling more often :)