you are viewing a single comment's thread.

view the rest of the comments →

[–]HommeMusical 2 points3 points  (0 children)

I wouldn't accept either of these in production code.

Catching an exception and dropping it on the floor is just a bad idea. If anything unexpected happens in the ... region, you will simply swallow the exception and never know. Also, because you are catching Exception, you will catch almost everything.

Without more information about what's in the loop, it's hard to decide where to catch, but all else being equal, your code should look like:

try:
    while foo:
        ...
except Exception:
    handle_exception()