0

dofile("x/y/m.lua")

dofile("x/y/p.lua")

if m.lua fails due to some issue , p.lua will not run at all, please give me some resolution that i can run both files even if the first one fails and have logs for both

2 Answers 2

1

Try

function dofile(name)
  local f,err=loadfile(name)
  if f==nil then print(err) end
  local ok,err=pcall(f)
  if not ok then print(err) end
end
Sign up to request clarification or add additional context in comments.

Comments

0

Use pcall to catch Lua errors, possibly like this:

local success, result = pcall(dofile, "foo.lua")

If success is false, the function failed and the error message will be in result. If success is true, the return values of dofile will be in result. You can add additional result variables. For example:

local success, result1, result2, result3 = pcall(dofile, "foo.lua")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.