class ExitWhenFailException(Exception):
"""
人为制造异常退出测试
"""
def __init__(self, messages):
self.messages = messages
class KKException(Exception):
"""
人为制造异常退出测试
"""
def __init__(self, messages):
self.messages = messages
def testk(number):
if number == 1:
raise ExitWhenFailException("Human made exception exit test ===>>> {0}".format("should not is 1"))
elif number == 2:
raise KKException(" kk KKException")
else:
print("go go !!!")
def test():
try:
testk(1)
except ExitWhenFailException as e:
print(e)
except KKException as e:
print(e)
except Exception as e:
print(f"error is : {str(e)}")
if __name__ == "__main__":
test()
python 异常
最新推荐文章于 2024-05-04 15:26:51 发布