![](/img/trans.png)
[英]Selenium Python - How do I handle the exceptions on popups regardless of the order and handle a null or empty search
[英]Handle exceptions fo empty or null input?
我正在研究一個 class 項目,以使用區塊鏈實施基本投票系統,但我對 python 中的異常處理不是很熟悉。我有一個用於我的選票的構造函數 class,它啟動兩個變量和一個 object:id、候選人和人。 如果這些變量/對象中的任何一個為空或有 null 輸入,我將如何拋出異常?
def __init__(self, person, id: int, candidate: str):
"""create and store the ballot instance using voter object and id"""
self.vote = {"ID": id, "SIG": person.hash, "CANDIDATE": candidate}
self._store_ballot(person.name)
您將不得不在某個時候測試您的值並使用關鍵字raise
來拋出想要的異常。 您可以使用內置異常之一或根據需要創建自定義異常。 在這里閱讀更多相關信息: https://docs.python.org/3/library/exceptions.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.