开发者

How do I print Python 2.5 Exception arguments?

开发者 https://www.devze.com 2023-01-20 21:11 出处:网络
Does python 2.5 allow you to pass exception arguments? try: raise Exception(\"argument here\") except Exception: print Exception.args

Does python 2.5 allow you to pass exception arguments?

try: raise Exception("argument here")
except Exception: print Exception.args

I've had no luck with the above code - I know this is how you do it in Python 2.7 - i开发者_开发知识库s this not in Python 2.5?


You aren't actually raising the exception, just creating it. Once you fix that, you also need to refer to the instance that gets raised, not just the Exception class:

>>> try: 
...     raise Exception('foo', 23)
... except Exception, e: 
...     print e.args
... 
('foo', 23)
0

精彩评论

暂无评论...
验证码 换一张
取 消