-- Basic syntax:
status, value = pcall(function, arg1, arg2, ...)
--[[ Where:
- pcall is used to add error handling to functions and works similarly to
try-catch (try-except) in other languages
- function is the function you want to run in protected mode
- arg1, arg2, ... are the arguments passed to function and should be strings
- pcall returns two values:
1. a boolean which indicates whether function was executed without errors
2. the return value of the function (or error message if an error
occurred inside the function block
]]--
if pcall(foo) then
-- no errors while running `foo'
...
else
-- `foo' raised an error: take appropriate actions
...
end