[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [proposal] debug.geterrfunc to get current error function
- From: David Manura <dm.lua@...>
- Date: Thu, 23 Feb 2012 21:20:42 -0500
On Sun, Mar 13, 2011 at 8:38 AM, GrayFace <email@example.com> wrote:
> [...] I need a way to get the current error function, that is, the one passed
> to the last lua_pcall
> [...] I think this "geterrfunc" should be a part of standard debug library
> and also part of C API.
I made a similar comment in my complaint about how tracebacks work
. Part of the complaint boils down to the failed expectation that
any code of the form
can be safely (with zero side-effects) refactored into
local ok, err = pcall(f, ...)
if not ok then error(err) end
Here's a typical use case:
local file = io.open('data.txt') -- allocate resource
. . .
local ok, err = pcall(callback) -- invoke user callback
. . .
file:close() -- release resource prior to error propagation
if not ok then error(err) end -- propagate