lua-users home
lua-l archive

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

In case anyone was wondering, this is what I settled on:

function throw(code, msg)
   local s,e,location = string.find(debug.traceback(), ".-\n.-\n(.-:.-):")
   if not s then location = "Unknown:0" end
   return {code,location,msg}

Then from in the code I use:

throw(code, "msg")

What comes out is a table:

err[1] is the code
err[2] is the location (filename:line)
err[3] is the message

You have to be careful with this though because if you don't use a protected call you won't get any meaningful error message at all.

// Chris