我想要某种形式的东西
try:
# code
except *, error_message:
print(error_message)
即我想有一个通用的除外块,该块可以捕获所有类型的异常并显示错误消息。例如。“ ZeroDivisionError:被零除”。有可能在python吗?
如果执行以下操作,我可以捕获所有异常,但不会收到错误消息。
try:
# code
except:
print("Exception occurred")
尝试这个:
except Exception as e:
print(str(e))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句