Get a 'clear' error message in Lua -


i using error function in quite few of functions , propagate error messages user. however, don't want include information where error occured exactly; information should go log files.

for example, have class manages connection server. if connection times out, calls

error("connection timed out!") 

the error message caught calling code via pcall. however, message contains not message passed, name of file caused error , line number:

common/net/enetclient.lua:21: connection timed out! 

the question is: there way retrieve error message itself, or have manually following:

local status, msg = pcall(somefunctionthatthrowserrors) if not status     local file, msg = msg:match("(.-:%d+): (.+)")     print("error: " .. msg) end 

cheers,

from documentation of error function:

error (message [, level])

terminates last protected function called , returns message error message. function error never returns.

usually, error adds information error position @ beginning of message, if message string. level argument specifies how error position. level 1 (the default), error position error function called. level 2 points error function called error called; , on. passing level 0 avoids addition of error position information message.

from stated in second paragraph, adding level of 0 error call result in desired output:

error("connection timed out!", 0) 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -