Catching exceptions from Python 2.4 to 3.x

S

Steven D'Aprano

Oh for the day I can drop support for Python 2.4 and 2.5...


I have some code that needs to run in any version of Python from 2.4
onwards. Yes, it must be a single code base.

I wish to catch an exception and bind the exception to a name.

In Python 2.6 onwards, I can do:

try:
something()
except Exception as err:
process(err)

But in 2.4 and 2.5 "as err" gives me a SyntaxError, and I have to write:

try:
something()
except Exception, err:
process(err)


Is there some other trick to grab the current exception from inside an
except block?
 
C

Cameron Simpson

| Oh for the day I can drop support for Python 2.4 and 2.5...
|
|
| I have some code that needs to run in any version of Python from 2.4
| onwards. Yes, it must be a single code base.
|
| I wish to catch an exception and bind the exception to a name.
|
| In Python 2.6 onwards, I can do:
|
| try:
| something()
| except Exception as err:
| process(err)
|
| But in 2.4 and 2.5 "as err" gives me a SyntaxError, and I have to write:
|
| try:
| something()
| except Exception, err:
| process(err)
|
|
| Is there some other trick to grab the current exception from inside an
| except block?

sys.exc_info ?
--
Cameron Simpson <[email protected]>

Peeve: Going to our favorite breakfast place, only to find that they were
hit by a car...AND WE MISSED IT.
- Don Baldwin, <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top