gpt4 book ai didi

Python:try-catch-else 不处理异常。可能的?

转载 作者:太空狗 更新时间:2023-10-29 17:10:14 24 4
gpt4 key购买 nike

我是 python 的新手,想知道我是否可以在不处理异常的情况下创建 try-catch-else 语句?

喜欢:

try:
do_something()
except Exception:
else:
print("Message: ", line) // complains about that else is not intended

最佳答案

以下示例代码向您展示了如何使用 pass 捕获和忽略异常。

try:
do_something()
except RuntimeError:
pass # does nothing
else:
print("Message: ", line)

关于Python:try-catch-else 不处理异常。可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10464118/

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