我试图在python 3.6.5中找到一种方法来执行此操作,这不受支持
try:
c=1/0
print (c)
except ZeroDivisionError, args:
print('error dividing by zero', args)
它说python 3.6.5不支持这种类型的语法
那么有没有办法获取异常的参数呢?
最佳答案
怎么样:
try:
c=1/0
print (c)
except ZeroDivisionError as e:
print('error dividing by zero: ' + str(e.args))
现在,逗号符号用于
except
多种类型的异常,并且它们必须放在括号中,例如:try:
c = int("hello")
c = 1 / 0
print(c)
except (ZeroDivisionError, ValueError) as e:
print('error: ' + str(e.args))
关于python - 如何获取异常参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50530645/