gpt4 book ai didi

python - 故意触发 excect block 是一种不好的形式吗

转载 作者:太空宇宙 更新时间:2023-11-03 11:07:08 26 4
gpt4 key购买 nike

<分区>

有没有更好的方法来做这样的事情:

class SpecialError(Exception):
pass

try:
# Some code that might fail
a = float(a)
# Some condition I want to check
if a < 0:
raise SpecialError
except (ValueError, SpecialError):
# This code should be run if the code fails
# or the condition is not met
a = 999.

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com