I followed the instructions for error handling at the antlr website http://www.antlr2.org/doc/err.html (it says antlr2 but I couldn't find an alternative for antlr4) and wrote the exception handling for my rule as below.
subStmt :
(visibility WS)? (STATIC WS)? SUB WS? ambiguousIdentifier (WS? argList)? endOfStatement
block?
END_SUB
;
exception
catch [RecognitionException ex] {
}
But when I try to generate the Parser for the grammar it fails as below: java -jar ../Downloads/antlr-4.7-complete.jar vba.g4 -package vba -o out error(50): vba.g4:500:4: syntax error: 'catch' came as a complete surprise to me while matching rule preamble
Any help is much appreciated.