I have implemented a simple natural language parser as part of my grails app to implement a command line interface where the user can enter commands such as 'Create a new user' and the application will carry out this task etc, I have created files such as:
Tokenizer.groovy
PartOfSpeechTagger.groovy
SyntacticAnalyser.groovy
SemanticAnalyser.groovy
CommandGenerator.groovy
whereby these are placed in src/groovy
Within my controller I have a run()
method that instantiates these parser classes and calls methods within these objects, like so :
def run()
{
def tokenizer = new Tokenizer()
def posTagger = new PartOfSpeechTagger()
def syntacticAnalyser = new SyntacticAnalyser()
def semanticAnalyser = new SemanticAnalyser()
def commandGenerator = new CommandGenerator()
//split command string into tokens
def words = tokenizer.getTokens(params.command)
def taggedWords = posTagger.tagWords(words)
... and so on
}
My question is I want to be able to send error messages back to the client that arise within these parser classes, e.g in Tokenizer
if an invalid Token
is found etc.
What is the best way for me to handle these errors, and sent them back to the broswer?
I have no previous experience in error handling at this sort of level, so any input is welcomed.
Initially I have thought of throwing a custom InvalidTokenException
and catching it in the controller, and rendering the text to the client, but this doesnt seem right?!
Any thoughts?