-- Define a function that may produce an error
function readFromFile(filename)
local file = io.open(filename, "r")
if not file then
error("File not found: " .. filename)
end
local content = file:read("*a")
file:close()
return content
end
-- Call the function with pcall
local success, result = pcall(readFromFile, "nonexistent.txt")
-- Check if the call was successful
if success then
print("File content:", result)
else
print("Error:", result)
end