gpt4 book ai didi

python - 报告 `try` 语句中未指定错误的类型/名称? python 2

转载 作者:太空宇宙 更新时间:2023-11-03 15:12:04 28 4
gpt4 key购买 nike

这是我的意思的一个简单示例 -

try:
something_bad

# This works -
except IndexError as I:
write_to_debug_file('there was an %s' % I)

# How do I do this? -
except as O:
write_to_debug_file('there was an %s' % O)

第二个异常的正确语法是什么?

提前致谢:)

最佳答案

except 异常为 exc:

Exception 是所有“内置的、非系统退出的异常”的基类,也应该是用户定义异常的基类。因此,except Exception 将捕获除少数不属于 Exception 子类的所有内容,例如 SystemExitGeneratorExit键盘中断

关于python - 报告 `try` 语句中未指定错误的类型/名称? python 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25235633/

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