7

Python 2.5 won't let me use this syntax:

try: code_that_raises_exception() except Exception as e: print e raise

So how should I print information about an exception?

Thanks

EDIT: I'm writing a plugin for a program that includes kind of a pseudo python interpreter. It prints print statements but doesn't show exceptions at all.

2 Answers 2

9

the 'as' keyword is a python 3 (introduced in 2.6) addition, you need to use a comma:

try: code_that_raises_exception() except Exception, e: print e raise 
Sign up to request clarification or add additional context in comments.

2 Comments

@Mike Axiak, what if you want to catch different exceptions which I'd usually do like ValueError as Verr, NameError as Nerr,...?
except (ExceptionA, ExceptionB), e ?
2
try: codethatraises() except Exception, e: print e raise 

not as easy to read as the latest and greatest syntax, but identical semantics.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.