[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modifing try-catch statement
- From: Ted Unangst <ted.unangst@...>
- Date: Sat, 18 Sep 2010 01:24:14 -0400
On Fri, Sep 17, 2010 at 11:28 PM, Quae Quack <quae@daurnimator.com> wrote:
> Looks like you just made xpcall:
>
> xpcall( function()
> -- try code
> if getvar() then
> else
> error(setmetatable({"an","error","object"},{__type="err"}))
> end
> end , function ( err )
> -- catch code, you can dispatch/swicth on err:
> if (getmetatable(err) or {}).__type == "err" then
> print(table.concat(err))
> else --propgate error
> error(err)
> end
> end )
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.