Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

python - Write in database on exception

I have the following code, if the try catch statement executed successfully then I write in my database model success = True and if the code Excepts then I want to write success = False. In purpose I raise the exception in order to test my except statement. The code goes successfully in the except statement because I get the print, but it does not write in my database.

try:
    ...do some work...
    models.SyncRun(success=True).save()
    raise Exception
except Exception as e:
    print("in")
    models.SuncRun(success=False).save()
    raise Exception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...