java - Correct way to add custom exception to Lexer/Parser files in antlr4 -


i have custom parsingexception(string message, int location, string offendingtext)

i want parser throw exception when parsing / lexing error encountered.

is correct ?

@parser::members {   @override   public void notifyerrorlisteners(token offendingtoken, string msg, recognitionexception ex)   {   throw new parsingexception(msg,offendingtoken.getstartindex(),offendingtoken.gettext());   } } @lexer::members {     @override     public void recover(recognitionexception ex)     {  throw new parsingexception(ex.getmessage(),getcharpositioninline(),ex.getoffendingtoken().gettext());         }           } 

i unhandledexception error this.

you should override syntaxerror method of baseerrorlistener instead of notifyerrorlisteners , recover decribed here: handling errors in antlr4.


Comments

Post a Comment

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -