lua-users home
lua-l archive

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


Fabien <fleutot+lua@gmail.com> writes:
>> NOTE if  'return' or 'break' exists in "cleanup block", it will not raise
>> the error object
>> but just do what "return" and "break" do.
>
> I'm not sure to understand: does it mean that the following program won't
> run the finally-block?
>
> *function *f(filename)
>    *local *h
>    *try*
>       h = io.open (filename)
>       *return *h:read '*a'
>    *finally*
>       *if *h *then *h:close() *end*
>    *end*
> *end*
> print(f "data.txt")

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.

[Your above example does not have a return or break in the finally-block.]

-Miles

-- 
Admiration, n. Our polite recognition of another's resemblance to ourselves.