I have adopted the LuaJSON to parse JSON. The parse call seems like that:
-- file.lua
local res = json.decode.decode(json_str)
if res == nil then
throw('invalid JSON')
end
...
But if the json_str
is badly formated, the decode()
will stop within LuaJSON and interrupt the execution of file.lua. I want the control flow to return to my function instead, so I can provide a custom error notification.
I have browsed the LuaJSON APIs, and there is no callback-like error handling. I want to know is there any Lua mechanism that allows me to handle errors occuring within LuaJSON from within file.lua?
decode
call. I was just trying to illustrate the use ofpcall
. – Obliquity