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:

Error Handling in Peakboard Script

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

We are learning from you!

Did you find this article helpful?

Be enlightened!

Do you need more support?

Peakboard Youtube icon Visit our YouTube channel

Our numerous videos for beginners and advanced users explain exactly how to design your dashboard.

Peakboard Templates icon Visit the Peakboard Templates

Download our templates for various use cases for free.

Peakboard icon Visit www.peakboard.com

Find out all about Peakboard and browse our different use cases and success stories.