What about try:except:finally

Thomas Wouters thomas at xs4all.net
Sat Jul 8 13:45:36 EDT 2000


On Sat, Jul 08, 2000 at 05:30:33PM +0100, Chris Withers wrote:
> Alan Daniels wrote:
> > >Does python support, or if not, would it be cool to have support for
> > >try/except/finally?
> > 
> > No, but just use try/except/else instead. Why it's "else" instead of
> > "finally", I have no idea, but this works just fine. Example:

> Actually, yes it does ;-)

> ...but it does something different. I read the discription on page 50 of
> David Beazely's Python Essential Reference, but it didn't make much
> sense to me :S

The 'else' is called 'else' because it's similar to the 'else' in 'if'
clauses and 'for' and 'while' loops: the 'else' clause of a 'try/except'
only gets executed when *no* exception occurs. 'finally', however, will
alway be called on the 'way out' of the try-block, wether something went
wrong or not.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list