📜  python代码示例中的循环错误

📅  最后修改于: 2022-03-11 14:46:24.136000             🧑  作者: Mango

代码示例1
try:
    # smallest block of code you foresee an error in
    response = language_client.analyze_sentiment(document=document) # I think your exception is being raised in this call
except InvalidArgument as e:
    # your trace shows InvalidArgument being raised and it appears you dont care about it
    continue # continue to next iteration since this error is expected
except SomeOtherOkayException as e:
    # this is an example exception that is also OK and "skippable"
    continue # continue to next iteration
except Exception as e:
    # all other exceptions are BAD and unexpected.This is a larger problem than just this loop
    raise e # break the looping and raise to calling function

sentiment = response.document_sentiment
sentimentscore_list.append(sentiment.score)
magnitude_list.append(sentiment.magnitude)
# Add the description that was actually used to the description list
description_list.append(descr)
# more code here...