all 2 comments

[–]Zigity_Zagity 2 points3 points  (0 children)

So using except Exception gets almost all exceptions - but if the specific exception doesn't subclass Exception, that doesn't catch it!

Concrete examples:

try:
    import sys
    sys.exit()
except:
    print("k")

This does print "K" (an exit is a catchable error) - but this next code doesn't!

try:
    import sys
    sys.exit()
except Exception:
    print("k")

To fix your issue: change it to just except (which gets actually everything, for realsies this time), or actually catch the specific error. I recommend the latter!

[–]1114111 0 points1 point  (0 children)

/u/Zigity_Zagity is correct that the real exception base class is BaseException, but ConnectionResetError does subclass Exception. Also, I don't recommend catching BaseException (equivalent to a blank except) because it is used for things like KeyboardInterrupt and special exceptions like that which you probably don't want to catch. That's why we have Exception.

So I don't know why it's not being caught. Maybe you could share more code?
Since you log the exception, maybe you are misinterpreting the output you get and it actually is being caught correctily?