Iterating through a list. Upon condition I want to move on to next item in list

Chris Angelico rosuav at gmail.com
Wed May 10 18:52:57 EDT 2017


On Thu, May 11, 2017 at 8:41 AM, Dan Stromberg <drsalists at gmail.com> wrote:
> On Wed, May 10, 2017 at 1:46 PM, MRAB <python at mrabarnett.plus.com> wrote:
>
>> NEVER use a 'bare except' to suppress exceptions! It'll catch _all_
>> exceptions, even NameError (if you've misspelled a name, it'll catch that
>> too). Catch only those exceptions that you're prepared to deal with.
>
> When writing many kinds of applications, this is great advice.
>
> But is it good when writing REST API's?  You don't want one buggy API
> call to bring down the whole service.
>
> Or am I missing something?

1) You should usually use "except Exception:" rather than a bare
except, even there.
2) When you create a boundary, *you log the exception*.

That's what you're missing. Simply *suppressing* all exceptions is a
terrible thing to do. It's common to have a web service boundary that
says "except Exception as e: log_exception(e); return HTTP(500)", but
that's not suppressing it, it's handling it.

ChrisA



More information about the Python-list mailing list