This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

error handling
#1
When decoding a json string you can get different errors.

Is this code the best way to handle errors? or is there a more generic way to do this?

Code:
if states and states ~= '' then
  local success, res = pcall(json.decode, states)
  if success then
    states = res
  end
end
Reply
#2
You can use json.pdecode which will return nil, err in case of an error:
Code:
res, err = json.pdecode(data)
Reply


Forum Jump: