Reputation: 417
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
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