Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33465 > unrolled thread
| Started by | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| First post | 2012-11-17 03:12 +0000 |
| Last post | 2012-11-17 15:53 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
Catching exceptions from Python 2.4 to 3.x Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-17 03:12 +0000
Re: Catching exceptions from Python 2.4 to 3.x Cameron Simpson <cs@zip.com.au> - 2012-11-17 14:26 +1100
Re: Catching exceptions from Python 2.4 to 3.x Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-17 15:53 +0000
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-11-17 03:12 +0000 |
| Subject | Catching exceptions from Python 2.4 to 3.x |
| Message-ID | <50a7009e$0$29978$c3e8da3$5496439d@news.astraweb.com> |
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?
--
Steven
[toc] | [next] | [standalone]
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2012-11-17 14:26 +1100 |
| Message-ID | <mailman.3770.1353122814.27098.python-list@python.org> |
| In reply to | #33465 |
On 17Nov2012 03:12, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
| 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 <cs@zip.com.au>
Peeve: Going to our favorite breakfast place, only to find that they were
hit by a car...AND WE MISSED IT.
- Don Baldwin, <donb@netcom.com>
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-11-17 15:53 +0000 |
| Message-ID | <50a7b309$0$29978$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #33466 |
On Sat, 17 Nov 2012 14:26:43 +1100, Cameron Simpson wrote: > On 17Nov2012 03:12, Steven D'Aprano > <steve+comp.lang.python@pearwood.info> wrote: > | Is there some other trick to grab the current exception from inside an > | except block? > > sys.exc_info ? Thanks, that is just what I was looking for. -- Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web