Python 2.5 允许传递异常参数吗?
try: raise Exception("argument here")
except Exception: print Exception.args
我对上面的代码没有运气 - 我知道这就是 Python 2.7 中的做法 - 这不是 Python 2.5 中的吗?
最佳答案
您实际上并没有引发异常,只是创建了它。一旦解决了这个问题,您还需要引用引发的实例,而不仅仅是 Exception 类:
>>> try:
... raise Exception('foo', 23)
... except Exception, e:
... print e.args
...
('foo', 23)
关于exception - 如何打印 Python 2.5 异常参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4002374/