r/badcode • • Jul 14 '21

python Try/Except in Python - Sigh

Post image
662 Upvotes

93 comments sorted by

View all comments

Show parent comment

4

u/BobHogan Jul 14 '21

In addition to what /u/war_against_myself said, a bare except in python will also catch interrupts like SIGKILL due to the exception class hierarchy in Python.

If you want to catch any exception, you should be using except Exception:. That will catch all exceptions, while still ignoring interrupts so you can still kill your code when you want to

3

u/ThatDudeBesideYou Jul 15 '21

Oh yea I am doing that, since logging it requires a reference so it always except Exception as e: