How do you assign an exception to a local variable in Python 2.5?
Asked Answered
S

1

8

In Python 2.6+, you can handle exceptions like this:

  try:
    # stuff
  except Exception as e:
    return 'exception %s' % type(e)

What is the equivalent in 2.5?

Sevier answered 25/5, 2011 at 14:33 Comment(0)
C
13

Like this :

try:
    # stuff
except Exception, e:
  return 'exception %s' % type(e)
Carmel answered 25/5, 2011 at 14:34 Comment(2)
I don't think you need to call str(), because you are already doing the interpolation using %s, 'exception %s' % type(e) will work just fineMarshallmarshallese
Edited my question as well. :)Sevier

© 2022 - 2024 — McMap. All rights reserved.