Scripting
Error Handling in Scripts
Error handling in Peakboard scripts is managed using the Try catch
block, found under Errorhandling
in the script editor. A Try catch
block consists of several parts:
- the
Try
section, where the code is executed and the return variables (error message, error type, and error code) are defined - the
Do
section where the main code is executed - the
Else
section where the error is handled.
The Try catch
block is used as follows:
When error handling is needed in a script, it is implemented as follows:
local errmsg = ''
local errtype = ''
local errcode = ''
if trycatchfn(function()
peakboard.log('Execution started')
end,
function(e)
errmsg = e.message
errtype = e.type
errcode = e.code
end)
then
peakboard.log('Execution successfully completed')
else
peakboard.log('Execution failed: ' .. errmsg)
end