[antlr-interest] Bug handling Exception and predicate

Peter Kronenberg PKronenberg at technicacorp.com
Mon Apr 11 06:26:15 PDT 2005


I think I found a definite bug in the 2.7.6 plugin code.  It occurs if
you want to catch your own exception and there is also a predicate
involved.  Here is a sample:

class TestTreeWalker extends TreeParser;

options {classHeaderPrefix = "public abstract";
	}
	
	{ public class MyException extends Exception {};
	  abstract public void throwEx() throws MyException;	
	
	}
	
	expr
	: #(A evalB C) {throwEx();} ;
	exception
             catch [MyException ex] {
                reportError(ex.toString());
             }
             
    evalB
    : (#(D E F)) => #(D E F)
    | #(D E);
-------
The generated code includes the following

public final void expr(AST _t) throws RecognitionException {
...
try {
...
}
catch (MyException ex) {
			if (inputState.guessing==0) {
				
				reportError(ex.toString());
				
			} else {
				throw ex;
			}
		}
--------
Note that MyException is rethrown, but the method signature does not
contain 'throws MyException'.  This results in a compiler error.
If you remove the predicate from 'evalB', the problem goes away


Peter Kronenberg
Software Engineer
(703) 885-1222
pkronenberg at technicacorp.com


The information contained in this transmission may contain privileged and confidential information. It is intended only for the use of the person(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Technica Corporation does not represent this e-mail to be free from any virus, fault or defect and it is therefore the responsibility of the recipient to first scan it for viruses, faults and defects. To reply to our e-mail administrator directly, please send an e-mail to postmaster at technicacorp.com. Thank you.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050411/b329f2fd/attachment.html


More information about the antlr-interest mailing list