One method to handle errors in Lua column map procedures is to encapsulate your code in the pcall (protected call) function. When there is an error, the pcall function returns a table object that contains the error code and error message. You can extract and print the error code and error message that are returned by the pcall function.
The example function shows how the pcall function can be used to handle errors. The code after the pcall function prints the error code and error message in the table object that is returned by the pcall function.
function cm_transform()
-- Protected invocation of optim.source.getcolumnvalue()
local status, result = pcall(optim.source.getcolumnvalue())
if status then
value = result
else
err = result
if type(err) == "table" then
if err.code ˜= nil then
optim.print("err.code: " .. err.code)
optim.print("err.message: " .. err.message)
else
error("err.code is nil")
end
else
optim.print("err: " .. err)
end
end
end