[antlr-interest] Passing user defined exceptions through the parser.
Peter C. Chapin
pcc482719 at gmail.com
Mon Jan 12 14:14:57 PST 2009
Sam Harwell wrote:
> Here's what I do. This is with the C# target so there are probably a few
> differences, but you'll get the idea.
>
> try
> {
> MyLexer lexer = new MyLexer( new ANTLRStringStream( text ) );
> CommonTokenStream tokens = new CommonTokenStream( lexer );
> MyParser parser = new MyParser( tokens );
> parser.program();
> }
> catch ( OperationCanceledException )
> {
> // ...
> }
>
I'm thinking that this works in C# because C# does not have statically
enforced exception specifications (I could be wrong... I know very
little about C#). In Java an attempt to throw OperationCanceledException
from a method invoked inside a rule will cause the parser to fail to
compile because the parser methods don't declare that exception in their
exception specifications.
Peter
More information about the antlr-interest
mailing list