Python Error message

Chris Angelico rosuav at gmail.com
Thu Aug 4 11:51:04 EDT 2016


On Fri, Aug 5, 2016 at 1:31 AM, GBANE FETIGUE <bemen77 at gmail.com> wrote:
> try:
>     parsed_response = json.loads(response)
>     print "Your applicationId is: " + parsed_response[u'applicationId']
>     version_id = parsed_response[u'versionId']
>     print "Your versionId is: " + version_id
> except:
>     print 'Seems the named application already exists!'
>     print 'Seems the named versionId already exists!'
>

This is a very bad idea. You're catching every possible exception and
printing out the same message for all of them. And then continuing
blithely on. Instead, catch ONLY the exceptions you really expect to
be seeing (I'm guessing KeyError here). If anything else goes wrong,
let the exception bubble up.

ChrisA



More information about the Python-list mailing list