lua-users home
lua-l archive

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


On 02/08/2013 12.40, Dmitry Pashkevich wrote:

Emphasis mine

Yeah BUT in my case I wanted to log an error via my own utility and then
call `error()` to get stack trace output and terminate the program. Some
parts of my code look like this:

    if somethingWrong then
         myLogger:log(Level.Error, extraData, "this isn't looking good!")

         error() -- hope to also get stack trace without extra calls

    end

But I'm probably making up a problem for myself...



What Dirk told you seems exactly what you're looking for. Just replace:

error()


with:


error ""


in that code and you'll get an unconditional error with a stack trace, tracing back to the point where you put that call.

If you, OTOH, need a custom error function producing a somewhat customized stack trace, you should build on debug.traceback.

-- Lorenzo