Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33466

Re: Catching exceptions from Python 2.4 to 3.x

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'subject:Python': 0.05; 'base.': 0.05; '"as': 0.07; 'try:': 0.07; 'missed': 0.09; 'python': 0.09; 'don': 0.09; 'err:': 0.09; 'exception,': 0.09; 'cc:addr:python-list': 0.10; 'bind': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:edu.au': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'simpson': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.17; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '2.6': 0.27; 'run': 0.28; "d'aprano": 0.29; 'steven': 0.29; 'code': 0.31; 'version': 0.34; 'there': 0.35; 'except': 0.36; 'but': 0.36; 'received:au': 0.36; 'charset :us-ascii': 0.36; 'drop': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'gives': 0.39; 'content-disposition:inline': 0.60; 'grab': 0.64; 'our': 0.65; 'wish': 0.70; 'day': 0.73; 'do:': 0.91; 'write:': 0.91
Date Sat, 17 Nov 2012 14:26:43 +1100
From Cameron Simpson <cs@zip.com.au>
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: Catching exceptions from Python 2.4 to 3.x
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <50a7009e$0$29978$c3e8da3$5496439d@news.astraweb.com>
User-Agent Mutt/1.5.21 (2010-09-15)
References <50a7009e$0$29978$c3e8da3$5496439d@news.astraweb.com>
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3770.1353122814.27098.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353122814 news.xs4all.nl 6891 [2001:888:2000:d::a6]:55723
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33466

Show key headers only | View raw


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>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web