[antlr-interest] Wondering about: Error handling

Oliver Zeigermann oliver at zeigermann.de
Mon Jun 18 05:45:16 PDT 2007


2007/6/18, Wincent Colaiuta <win at wincent.com>:
> El 18/6/2007, a las 2:14, Terence Parr escribió:
>
> > On Jun 18, 2007, at 6:13 AM, Oliver Zeigermann wrote:
> >> When I want special handling for certain exceptions only I can
> >> specify
> >> that in the catch phrase. Like that:
> >>
> >> catch [FailedPredicateException fpe] {
> >> ...
> >> }
> >>
> >> However, this replaces the orignal catch block instead of being
> >> added.
> >> I expected something like this to be generated:
> >>
> >>
> >>     catch (FailedPredicateException fpe) {
> >>       ...
> >>        }
> >>      catch (RecognitionException re) {
> >>            reportError(re);
> >>            recover(input,re);
> >>        }
> >>
> >> But only the first block actually is generated.
> >
> > Interesting.  Hmm...I guess that was my intended behaviour but I
> > can see how it would be confusing.  OTOH, I can't always look at
> > the exception names inside and determine for an arbitrary target
> > what's up.  In fact, ANTLR's code generator can't assume anything.
>
> At least as a straightforward workaround you can just include the
> RecognitionException catch block in your own override if that's the
> behaviour that you want...

Yes. That sounds reasonable and sufficient.

Thanks

Oliver


More information about the antlr-interest mailing list