簡體   English   中英

失敗后,Python繼續執行腳本

[英]Python continue script after failure

我正在為Atlassian的隱藏應用程序使用python api。

該腳本無法刪除項目,因為它內部有存儲庫,然后退出。

Traceback (most recent call last):
  File "stash.py", line 38, in <module>
    stash.projects[p["key"]].delete()
  File "<string>", line 2, in delete
  File "/usr/local/lib/python2.7/site-packages/stashy/errors.py", line 46, in ok_or_error
    maybe_throw(response)
  File "/usr/local/lib/python2.7/site-packages/stashy/errors.py", line 40, in maybe_throw
    raise e
stashy.errors.GenericException: 409: {u'errors': [{u'message': u'The project "TEST" cannot be deleted because it has repositories.', u'exceptionName': u'com.atlassian.bitbucket.IntegrityException', u'context': None}]}

是否可以顯示錯誤但繼續執行腳本?

它被稱為try .. Expect模式或Python中的異常處理

最簡單的形式:

try:
    stash.projects[p["key"]].delete()
except Exception as e:
    print(e)

更多信息:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM