> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of BiGNoRm6969
> Sent: Thursday, June 10, 2010 7:09 AM
> To: [email protected]
> Subject: [antlr-interest] How catch exception when "extraneous input"
> happens?
> 
> 
> 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?


When the parser recovery code discovers that it can 'correct' the input stream 
by either inserting a token it manufactures, or skipping an extra token, then 
it issues the error message as normal but it does not throw an exception 
because it can just carry on. So can override the recover methods and force a 
throw if you need that, but if you are just wanting to print your own message, 
then you just override displayRecognitionError() 

Jim




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to