[Tutor] capturing error msg in exception

Adam Bark adam.jtm30 at gmail.com
Sun Jun 27 19:29:41 CEST 2010


On 27 June 2010 18:22, Steve Willoughby <steve at alchemy.com> wrote:

> On 27-Jun-10 10:12, Adam Bark wrote:
>
>> On 27 June 2010 17:47, Payal <payal-python at scriptkitchen.com
>>
>
>     c. What is the correct Python of writing,
>>    except  as e: print 'Msg : ' , e        # Capturing all exceptions
>>
>
> Since exceptions are (should be?) subclasses of Exception, you can do:
>
> except Exception as e:
>
>
>  I think the 'as' syntax is only available in Python 3.x
>>
>
> It's in Python 2 as well.  At least I see it in 2.6.4, probably earlier too
> (but I'm not sure ATM how early it showed up).
>
>
Ah yeah sorry I got confused, it's the comma version that is gone from 3.x
isn't it? I assume that means 'as' is the preferred syntax.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100627/19143fba/attachment-0001.html>


More information about the Tutor mailing list