lua异常捕获

解析json失败,想要捕获异常,可以使用pacll

      local str = '[{"name":"fjd","age":110},{"date":"2017-04-25","age":111,"name":"wyc"}]'
      local err,tbl = pcall(function(str)return cjson.decode(str)end,str)

正常err返回true,tbl是正常的结果。错误err返回FALSE,tbl返回错误信息,如Expected colon but found invalid token at character 10

posted @ 2017-04-25 11:23  mentalidade  阅读(2761)  评论(0编辑  收藏  举报