【问题标题】:Getting exception details [duplicate]获取异常详细信息[重复]
【发布时间】:2018-10-05 13:12:53
【问题描述】:

我知道我可以在 python 中捕获异常,例如:

try:
    with open('file.log') as file:
        read_data = file.read()
except:
    print('Exception!')

但是如何获取异常类型或错误信息呢?

【问题讨论】:

    标签: python


    【解决方案1】:
    try:
        with open('file.log') as file:
            read_data = file.read()
    except Exception as e:
        print(e)
    

    您必须将异常转换为变量。 Python documentation.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多