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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -