[antlr-interest] Passing user defined exceptions through the parser.

Laurent Caillette laurent.caillette at gmail.com
Tue Jan 13 00:39:43 PST 2009


This should work if you make OperationCanceledException a subclass of
RecognitionException, which is a checked exception thrown by parser's
methods. Then the catch clause does its job.

c.

On Mon, Jan 12, 2009 at 11:14 PM, Peter C. Chapin <pcc482719 at gmail.com> wrote:
> 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
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list