0
votes

I am an ANTLR newbie. Here is a grammar for which I am trying to write a Visitor class.

grammar extremelysimpleexpr ;

stat : expr ;
expr : sub ;
sub : add ( '-' add )* ;
add : VAL ( '+' VAL )* 
    | VAL
    ;  


VAL : [0-9]+ ;
[ \t\n\r]+ -> skip ;

Vistor.java

 .........
  public Integer vistAdd(ctx) {
       if (some cond) {
          throw new Exception()
       }
  }
 ..........

The problem is I am not able to throw exception since the generated code does not handle exceptions, the method signature does not have throws exception in its signature. Is there any way out of it ?

1

1 Answers

0
votes

An unchecked exception would work, as suggested by Sam Harwell - as one of two options - here. I just tried it.

You can catch that exception wherever you want.