[antlr-interest] How catch exception when "extraneous input" happens?

Ron Hunter-Duvar ron.hunter-duvar at oracle.com
Thu Jun 10 07:55:40 PDT 2010


BiGNoRm6969 wrote:
> During a string validation, I receive this message "line 1:20 extraneous
> input 'f' expecting ASA" in the console. This is printed by the
> "getErrorMessage" function, initiated by the "match" function. I understanrd
> why this message is displayed. 
>
> My problem is that I want to catch the error generated by the parser. I
> include this code in my .g:
>
> @rulecatch {
>        catch ( RecognitionException testing ) {
>            throw testing;
>        }
>   }
>
> I also include a try/catch block in my Java code that use my parser, to
> catch the RecognitionException exception. However, it never catch it. So, my
> program is unable to know if the validation succeed or not.
>
> What I am  missing?
>
>
>   
Try overriding either the emitErrorMessage or the 
displayRecognitionError method in org.antlr.runtime.BaseRecognizer. You 
can do that with an @member section in your grammar, or in a separate 
superclass.

Ron

-- 
Ron Hunter-Duvar | Software Developer V | 403-272-6580
Oracle Service Engineering
Gulf Canada Square 401 - 9th Avenue S.W., Calgary, AB, Canada T2P 3C5

All opinions expressed here are mine, and do not necessarily represent
those of my employer.



More information about the antlr-interest mailing list