error raises. pcall catches.
Goal
Catch a thrown error and print it.
local ok, err = pcall(function()
error("empty till")
end)
print(ok)
print(err)local ok, result = pcall(function()
return 12 * 40
end)
print(ok, result)local function need_city(city)
if city == nil or city == "" then
error("city required")
end
return city
end
print(need_city("Nairobi"))
local ok, err = pcall(need_city, "")
print(ok)
print(err)print(pcall(function() return 1 + 1 end))