假设-
a, b, c, d = 2, 0, 3, "$"
try:
print (a//b)
except ZeroDivisionError as e:
print (e)
try:
print (c//d)
我知道这是一个类型错误,但是如何在不知道预期会出现什么错误的情况下打印错误语句?谢谢。
最佳答案
您可以使用基本Exception
捕获其他错误:
a, b, c, d = 2, 0, 3, "$"
try:
print (a//b)
except ZeroDivisionError as e:
print (e)
except Exception as e:
print (e)
关于python - 在处理异常时,如何打印出现的任何错误声明?请参阅下面的更多细节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43942482/