[antlr-interest] Question about throwing subclassed exceptions in TreeParser

Ted Villalba ted.villalba at gmail.com
Wed Oct 3 09:11:15 PDT 2007


Hi all, I was inadvertently importing and mixing up 2 versions of
RecognitionClasses ( 2.6 and 3.0), and my dominoes were crashing.
This should work , if you don't do what I did.

Thanks for the time, sorry for the spam.

Ted

On 10/3/07, Ted Villalba <ted.villalba at gmail.com> wrote:
>
> Hi,
>
> I have a tree grammar that makes remote calls to validate info in my
> parsed grammar.I would like to be able to customize the messages in the
> exceptions that may result from these calls.
> To do so I have subclassed RecogntitionException. Perhaps there is another
> way to add custom messages to the RecognitionException, this would be the
> easiest solution for me...I guess. I could not figure out how to do so, so I
> subclassed the exception.
> The problem I have now is when trying to throw the subclassed exception.
> I am using the rulecatch action to percolate the RecognitionException up
> to the calling code, but, copying the code from the book that throws
> RecognitionExceptions, I don't know how to throw any other exceptions.
> I have :
> @rulecatch {
>   catch (RecognitionException e) {
>     throw e;
>   }
> }
>
> I have declared the following exception:
>
> import org.antlr.runtime.IntStream;
> import antlr.RecognitionException ;
>
> public class ANTLRInvalidYear extends RecognitionException {
>
>     protected String msg;
>
>     public ANTLRInvalidYear(String msg, IntStream input) {
>         super(input.toString());
>         this.msg = msg;
>     }
>
>     public String getMsg() {
>         return this.msg;
>     }
>
> I can catch this exception in my tree rules, but then am unable to throw
> it because the throw from the rulecatch seems restricted to the
> RecognitionException type.
> I may be missing something obvious. Any assistance is much appreciated.
>
> Thank you,
> Ted
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071003/4ae31429/attachment.html 


More information about the antlr-interest mailing list