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

Erik python at lucidity.plus.com
Wed May 10 18:49:52 EDT 2017


On 10/05/17 23:41, Dan Stromberg 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?

Yes. You are missing that you now have no idea what the code will go on 
to do if it ignores the error. You now have a program that is running in 
an entirely unexpected and unaccounted for state.

Perhaps it will be benign.

But, perhaps it will wipe an important part of the disk of your server 
because a string that is expected to contain the name of a subdirectory 
to be deleted actually still contains the root directory of your 
application. That's a *much* harder way of "bringing down the whole 
service" than having to just re-start the server process (which should 
be an automatic thing anyway) ...

E.



More information about the Python-list mailing list