lua-users home
lua-l archive

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


On Sat, Sep 18, 2010 at 9:15 AM, David Manura <dm.lua@math2.org> wrote:
> On Sat, Sep 18, 2010 at 1:24 AM, Ted Unangst <ted.unangst@gmail.com> wrote:
>> Calling error in xpcall results in a stack overflow, because the error
>> handler is still in effect while it's running.  This is arguably a
>> bug.  The manual says it calls f in protected mode, but doesn't say
>> the same about err.
>
> Though it doesn't say explicitly, and maybe it should, the behavior of
> xpcall I think is implied by lua_pcall, which can return LUA_ERRERR
> "error while running the error handler function."

Now it sounds like you are implying that LUA_ERRERR would be called
the first time error() is raised.  Try the lua code below.

function bad()
        print("starting")
        error("this error is expected")
end

function recov(e)
        print("got err", e)
        error("double boom")
end

print("here we go...")
print("xpcall", xpcall(bad, recov))
print("all done")

Based on your description, what output do you predict?  Here's the
output I actually get:

here we go...
starting
got err e.lua:3: this error is expected
got err e.lua:8: double boom
....
got err e.lua:8: double boom
got err C stack overflow
got err e.lua:8: double boom
....
got err e.lua:8: double boom
xpcall  false   error in error handling
all done

Yes, xpcall does eventually return "error in error handling", but not
when I would have anticipated.

Running with luajit2, I get much simpler behavior, which sounds more
like what you think regular Lua should do as well.

here we go...
starting
got err e.lua:3: this error is expected
xpcall  false   error in error handling
all done