lua-users home
lua-l archive

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

2011/11/18 Mak Nazečić-Andrlon <>:
> I know, but I don't think that's very much in the spirit of Lua.

It certainly is.
Just add a useful __tostring to your error objects.
A possibly useful piece of code:
local err_methods = { }
local err_mt = {
	__index = err_methods ;
	__tostring = function ( o ) return o:tostring ( ) or "No error message" end ;

function new_err ( t )
	return setmetatable ( t or { } , err_mt )

I for one would love some error object standardisation though:
eg, some common fields:
fatal = boolean
origin = string: name of library that raised the error
type = string: each function that raises an error should document the
"type"s of error it can raise ==> leading to nicer error catching