lua-users home
lua-l archive

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


> local function trace( str )  return io.stderr:write( str )  end
> local body = function( )
>   trace 'B'
>   while true do  trace '.' ; t = { }  end
>   trace 'X1'
> end
> local handler = function( )  trace "H"  end
> -- set up delayed error
> t = setmetatable( {}, {
>   __gc = function()  trace "E" error "blergh!" trace "X2"  end
> } )
> -- run
> trace "A"
> xpcall( body, handler )
> trace "Z"
> -- end testcase #1 --
> 
> There's three possible results that I'd expect
> 
> E1: AB....(forever)
> E2: AB....(exit)
> E3: AB....(etc.)....EHZ
> 
> But what I actually get is:
> 
> A1: AB....(etc.)....EZ
> A2: AB..EZ  (with HARDMEMTESTS)
> 
> i.e. the error handler doesn't run.

This one is correct, although the behavior is not documented.  When
there is an error inside a finalizer, the handler is not called.
(The rationale is that, more often than not, the handler is used to
locate the error [e.g., to build a traceback], but errors in finalizers
have no relation to where the code is when the error happens.)

-- Roberto