Question

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 - is this not in Python 2.5?

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top