[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: suggesting change: lua_pcall error handlers to return multiple values
- From: David Manura <dm.lua@...>
- Date: Thu, 22 Jan 2009 23:07:57 -0500
On Thu, Jan 22, 2009 at 5:09 PM, Asko Kauppi wrote:
> Lanes 2.0.3 will be able to provide this API to users:
> [...]|[ nil, err, stack_tbl ]= lane_h:join( [timeout_secs] )
> stack_tbl is an array of "<filename>:<line>" strings, describing
> where the error was thrown. Use table.concat() to format it to your liking
> (or just ignore it).
>
> Asko Kauppi kirjoitti 22.1.2009 kello 21:30: ...
>> Why not allow an error handler return multiple values? What I have in
>> mind is two (error value + stack trace string).
I was going to suggest instead that the error handler function store
the stack table inside the error object:
local ok, err = xpcall(f, improvedtraceback)
if not ok then
local stack_tbl = err.stack
print(tostring(err), tostring(stack_tbl))
end
but that won't work if the error object is a string (e.g. errors
thrown by Lua such as out-of-memory errors).
Anyway, having the error handler function return a stack table rather
than a stringified version of the stack table might help formatting
problems with nested xpcalls:
> return xpcall(function() local ok, err = xpcall(function() error '123' end, debug.traceback) error(err) end, debug.traceback)
false stdin:1: stdin:1: 123
stack traceback:
[C]: in function 'error'
stdin:1: in function <stdin:1>
[C]: in function 'xpcall'
stdin:1: in function <stdin:1>
[C]: in function 'xpcall'
stdin:1: in main chunk
[C]: ?
stack traceback:
[C]: in function 'error'
stdin:1: in function <stdin:1>
[C]: in function 'xpcall'
stdin:1: in main chunk
[C]: ?