Dealing with exceptions

Chris Angelico rosuav at gmail.com
Sat Mar 2 20:04:02 EST 2013


On Sun, Mar 3, 2013 at 11:41 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> But yes, in general, only catch the minimum you *know* you need to catch
> and can deal with. Anything else is a bug in your code that needs to be
> fixed, and you can't fix it if you never see the exception.

With the exception (if you'll excuse the expression) of "framework"
systems, where there's a distinct separation between "inside" and
"outside". Often then, the "outside" will catch any exception thrown
by the "inside" and deal with it in some generic way (for instance, a
web server might log the details and return HTTP 500 to the client,
then go back and handle the next request). Effectively, this is doing
the job of the top-level exception handler: log the exception (to the
console) and terminate.

ChrisA



More information about the Python-list mailing list