Re: try...finally is more powerful than I thought.

From: Bob Gailer (bgailer_at_alum.rpi.edu)
Date: 11/10/03


Date: Sun, 09 Nov 2003 16:02:07 -0700
To: Alan Kennedy <alanmk@hotmail.com>, python-list@python.org


At 07:51 AM 11/7/2003, Alan Kennedy wrote:

>[Brian Kelley]
> > How is [try..finally] working internally? Does
> > the finally get executed when try code block goes out of scope? This
> > would happen during a return or an exception which could explain the
> > magic.
>
> >From the Python Language Reference
>
>http://www.python.org/doc/current/ref/try.html
>
>"""
>The try...finally form specifies a `cleanup' handler. The try clause
>is executed. When no exception occurs, the finally clause is executed.
>When an exception occurs in the try clause, the exception is
>temporarily saved, the finally clause is executed, and then the saved
>exception is re-raised. If the finally clause raises another exception
>or executes a return or break statement, the saved exception is lost.
>A continue statement is illegal in the finally clause. (The reason is
>a problem with the current implementation - this restriction may be
>lifted in the future). The exception information is not available to
>the program during execution of the finally clause.
>"""

Which is followed by """When a return, break or continue statement is
executed in the try suite of a try...finally statement, the finally clause
is also executed `on the way out.' A continue statement is illegal in the
finally clause. (The reason is a problem with the current implementation --
this restriction may be lifted in the future).""" which is what applies to
the examples cited above.

Bob Gailer
bgailer@alum.rpi.edu
303 442 2625



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.537 / Virus Database: 332 - Release Date: 11/6/2003


Relevant Pages

  • Re: Finally in IE
    ... If an exception is thrown, each catch clause is inspected in turn ... the clause executes wether or not an exception is thrown ... Firefox considers your <script> block as self-enclosed system. ...
    (comp.lang.javascript)
  • SqlDataAdapter.Fill returns results of previous command
    ... This code executes successfully at certain points in the application, ... I don't know what the cause of this exception is yet, ... stored procedure was indeed executed on the database. ... The trace shows that the last action on the db was the stored ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: try...finally is more powerful than I thought.
    ... When no exception occurs, the finally clause is executed. ... or executes a return or break statement, ...
    (comp.lang.python)
  • Re: Multiple Catches in Try/Catch
    ... > one catches the particular exception that was thrown, ... it executes the Finally block if it is present. ... > <log fatal error> ... > Exit Function ...
    (microsoft.public.dotnet.languages.vb)