Raise an error

Verified
Added by iNTERFACEWARE

Use the error() function to raise an error and write it to the logs

Source Code
   -- raise an error
   error('Hello World I am an ERROR')
   
   -- The "level" param is very useful to make
   -- errors more visible when you are debugging
   
   -- raise error up one level at the calling function  
   error('Hello World I am an ERROR', 2)
   
   -- raise error up 2 levels
   error('Hello World I am an ERROR', 3)
   
   -- raise error at current level
   error('Hello World I am an ERROR', 1)
   -- equivalent to no level param specified
   error('Hello World I am an ERROR')
Description
Use the error() function to raise an error and write it to the logs
Usage Details

Raising an error in Lua is incredibly simple, just the error() function. The error() function is dual-purpose: It raises an error and at the same time writes it to the Iguana log. The function has two parameters: The first is the error text, the second is the level that the error is displayed. The level can be quite helpful when debugging as you can control which “level” the error is displayed (for example, you can cause an error to show in main() instead of within a module which makes for easier code development as you don’t need to swap into the module to view the error).

The level parameter is used to specify which level the error is displayed: level = 2 displays at the error at calling function, level = 3 displays two levels up, etc (level = 1 shows the error on the line where you call the error() function, exactly the same as not specifying a level). OK I admit that sounds confusing, but just try it and then it will be really obvious…

How to use the snippet:

  • Paste the desired error() statement into your script