[antlr-interest] Throwing a exception in a rule

Gavin Lambert antlr at mirality.co.nz
Wed Aug 29 05:43:52 PDT 2007


At 00:30 30/08/2007, Alexandre Hamez wrote:
 >I try to declare a rule that throws an exception, but when I 
look
 >at the generated code, the corresponding method doesn't throws 
this
 >exception. The code is the following:
[...]
 >So, am I missing something?

IIRC, currently v3 does not implement throw specs.  (And I'm not 
sure if it supports catch blocks yet either.)

The simplest workaround at the moment is to make sure that 
whatever you're trying to throw derives from 
RecognitionException.  (If need be you can catch it outside the 
lexer/parser and convert it to some other type if you don't want 
other code to have to deal with RecognitionExceptions.)



More information about the antlr-interest mailing list