lua-users home
lua-l archive

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


I'm trying to write user-friendly reportying of Lua error.
want to print stack trace to the screen and also to log file.
When using code shown below, stack trace do not saved to logfile.
I'm sure that is because _ERRORMESSAGE does some extra formatting.

How can I print stack trace to dump_error() ?


std_error_handler = _ERRORMESSAGE

safe_call_handler = function(errstr)
	F("While %s", EMSG)
	local s = format("While %s: %s", EMSG, errstr)
	dump_error(s) -- this won't print stack trace
	std_error_handler(errstr) -- this one prints stack trace
	EMSG = nil
end

safe_call = function(func, emsg, ...)
	EMSG = emsg
	return call(func, arg, 'x', safe_call_handler)
end

function dump_error(s)
	local fd = openfile("/tmp/LDUMP", "w")
	write(fd, s)
	write(fd, "\n")
	closefile(fd)
end


-- 
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.