News for hackers. Stuff that matters.
Re:Postmodern Error Handling in Python 3.6 by raverbashing on Saturday February 25, 2017 @05:11AM (#13730915)
You should have (+/-) one "except Exception" in your code which would be the "catch all/log error" thing.

But for how to do with errors, see the sibling comments to this one, and good libraries will give you an inheritance tree of exceptions

Re:Postmodern Error Handling in Python 3.6 by nicolaslem on Saturday February 25, 2017 @05:36AM (#13730969)
This is basically the equivalent of returning a 500 or failing a task. You know that your code failed somewhere but there is no way you can recover from it (granted your code is not idempotent so retrying everything is not an option).

By catching all exceptions as close as possible of the request you make, you can at least do something about it.

As for the tree of exceptions, it works well for a while until networks become unreliable, until remote peers start presenting certificates broken in subtle ways... You end up adding ranges of exception in the except clause as new ones are popping on Sentry. Then you get tired of it so you catch "Exception".

This is the unfortunate story of every single project I do that deals with network calls on the Internet.

Re:Postmodern Error Handling in Python 3.6 by rgacote on Saturday February 25, 2017 @09:37AM (#13731742)
Where 'in your code' is a module. Then log the exception and raise a new exception with a module-specific code. requests.exceptions.RequestException is a good example.

My modules do catch SystemExit and KeyboardInterrupt before the bare exception and simply re-raise those.