[antlr-interest] I want to throw an exception and stop parse, please!

Kevin Chen bestgembler at hotmail.com
Sun May 31 07:52:56 PDT 2009


Hello Tilman Bender, thanks for your tips!      :-)
I clean forgot unchecked exception.... I'm so stupid....     !!!- -
I get it!!!!!!!!!!!   :-)

>Hi Kevin,>
>Yes you can, but it is a bit of a dirty hack:>Make your custom Exception subclass RuntimeException. >This has two effects:>
>- The compiler will allow you to throw it in the recover method allthough recover has no throws declaration (RuntimeExceptions are unchecked)>- You cannot directly catch MyException in the code that invoked your parser, since the compiler will complain, that none such Exception is declared to >be thrown.>
>So that means:  Subclass RuntimeException and in the code calling your parser catch RuntimeException and gracefully exit your compiler/interpreter/whatever.
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090531/a236390a/attachment.html 


More information about the antlr-interest mailing list