[antlr-interest] ANTLR exception rethrowing
zieren at gmx.de
zieren at gmx.de
Thu May 2 12:22:00 PDT 2002
Hi,
I've got a question about exception handling in tree parsers (Java code
generator). When an exception handler is attached to a rule, ANTLR
generates corresponding catch statements. Now, if the tree parser uses
syntactic predicates, the generated code looks like this:
------------------------------schnipp------------------------------
try { // for error handling
exc1 = _t==ASTNULL ? null : (AST)_t;
b=tCondition(_t); // this rule throws UndefinedVariableException
_t = _retTree;
}
catch ( UndefinedVariableException undefVarEx ) {
if (inputState.guessing==0) {
// do something...
} else {
throw undefVarEx ; // <-- this is what I don't understand
}
}
------------------------------schnapp------------------------------
Why is the caught exception rethrown? Since it is not derived from
antlr.RecognitionException, I now have to declare it in the rule's throws
clause. But I want the rule itself to handle the exception. How do I go
about this?
Is this maybe a design fault? Should I - in a tree parser - only throw
exceptions derived from antlr.RecognitionException, which every rule
throws anyway?
Hmm... come to think of it... if inputState.guessing != 0, meaning that
the tree parser is testing for a syntactic predicate, isn't it impossible
that any exception other than antlr.RecognitionException (and subclasses)
is thrown?
Hope I made myself clear & thanx in advance for any help!
Greetings,
Jörg
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list