lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Yes, that's exactly I mean.

To simply explain, let's define the term "t-block" and "f-block" as:


function (f, msg)
  try
    "t-block"
  finally
    "f-block"
  end
end


the "f-block" will be executed in the following case, just before the
control flows out of the "t-block":
1) control-flow reaches the end of "t-block"
2) "break" or "return" from the "t-block"
3) error occurs from the "t-block"; IN THIS CASE, the error will be
re-thrown after the "t-block" executed. BUT "break" and "return"
statement in "f-block" will clear the error object and just jump out
of "f-block", so the error is ignored.

To sum up, f-block will be run whenever the control-flow leaves
t-block. After that, control goes where in t-block it intended to go.
just like the f-block is transparent. Unless in f-block we use "break"
or "return" or error(..) , etc. to change to control-flow explicitly.
Of course, if you call os.exit() in t-block, f-block will not get a
chance to execute. You call os.exit() in f-block, error will not be
re-thrown too.


On Jan 31, 2008 3:04 AM, Miles Bader <miles@gnu.org> wrote:
> It sounded to me like he meant that if a return or break occurs in the
> _finally_ block, and an error causes the finally-block to be executed,
> then that return/break will cause the error not to be rethrown at the
> end of the finally block.  In other words, the "error rethrowing" part
> of "finally" requires that control-flow reach the the end of the
> finally-block.
>
> -Miles