bboy3577
bboy3577

Reputation: 417

Continue running a script after finding an error

One of the most annoying things about errors is that one simple syntax error will kill all of my program. For example, if I do this:

require 'moduleWithSyntaxError' --Has a syntax error
require 'fullyFunctioningModule' --No syntax errors

foo = faultyClass.new() --Has syntax error inside the class definition
bar = normalClass.new() --No syntax errors

Then if the program finds a syntax error in the faulty module, it quits, and if it finds a syntax error in the faulty class, it quits. This brings my to my question, is there any way I can detect whether there was a syntax error, and use that information to not call faultyClass.new(), in a similar syntax to exceptions? I'm looking for something like this (yes this is very similar to C++ exceptions):

try()
    require 'moduleWithSyntaxError'
catch (exception)
    print (exception.what())
end

Upvotes: 1

Views: 2909

Answers (2)

Tom Blodget
Tom Blodget

Reputation: 20772

If you are truly talking about syntax errors, then simply running luac on Lua each file in your project will tell you if you have errors. (You could automate that.)

You wouldn't need exception handling to detect syntax errors unless you don't control the source code for the modules that the project runs.

Upvotes: 0

Youka
Youka

Reputation: 2705

Short and simple answer: pcall

It's exception handling in Lua.

Upvotes: 2

Related Questions