Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'subject:Python': 0.06; 'python': 0.08; 'ah,': 0.09; 'bind': 0.09; 'elegant,': 0.09; 'exception': 0.12; 'case.': 0.15; 'great!': 0.16; 'wrote:': 0.16; '>>>': 0.18; "haven't": 0.20; 'header:In-Reply-To:1': 0.22; 'versions': 0.23; "i'm": 0.27; 'work:': 0.29; 'yes.': 0.30; 'thanks': 0.30; 'error': 0.32; 'actually': 0.33; 'there': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.33; '...': 0.34; 'header :User-Agent:1': 0.34; 'try:': 0.34; 'pretty': 0.35; 'but': 0.37; 'think': 0.38; 'steven': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.39; "i'd": 0.40; "it's": 0.40; 'course.': 0.63; 'subject:name': 0.67; 'received:62': 0.70; 'from:addr:t': 0.84; 'subject:Catch': 0.91; 'subject: +': 0.93 Date: Sat, 27 Aug 2011 11:57:58 +0200 From: Thomas Jollans User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Catch and name an exception in Python 2.5 + References: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> X-Enigmail-Version: 1.3.1 OpenPGP: id=5C8691ED Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314439072 news.xs4all.nl 2423 [2001:888:2000:d::a6]:51263 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12257 On 27/08/11 05:45, Steven D'Aprano wrote: > Thomas Jollans wrote: > >> On 26/08/11 21:56, Steven D'Aprano wrote: > >>> Is there any way to catch an exception and bind it to a name which will >>> work across all Python versions from 2.5 onwards? >>> >>> I'm pretty sure there isn't, but I thought I'd ask just in case. >> >> It's not elegant, and I haven't actually tested this, but this should >> work: >> >> try: >> ... >> except (ValueError, KeyError): >> error = sys.exc_info()[2] > > Great! Thanks for that, except I think you want to use [1], not [2]. Ah, yes. Of course.