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

From: Alan Kennedy (alanmk_at_hotmail.com)
Date: 11/07/03


Date: Fri, 07 Nov 2003 14:51:08 +0000


[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.
"""

The Language Reference is very readable, not excessively formal, and
well worth a read.

http://www.python.org/doc/current/ref/ref.html

regards,

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan


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)
  • 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, ... (The reason is a problem with the current implementation -- ...
    (comp.lang.python)
  • 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: 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)