[antlr-interest] jars and exceptions

xserty xserty at yahoo.it
Mon Apr 19 03:59:16 PDT 2004


Hi all,
 Hope somebody can help me with these problem...

I'm trying to develop a plugin for jEdit that parses a formula using
antlr.

I'm working on two "seperate" projects, say ParserProject and
ParserPluginProject.
- ParserProject is the (generated) parser which relies on antlr
(included in an external jar) and throws exceptions defined in
antlr.jar.
- ParserPluginProject is a GUI plugin for that parser, so it relies on
ParserProject.jar and antlr.jar (I have included these in
ParserPluginProject's classpath).

I compiled ParserProject and made a jar out of it - ParserProject.jar
- (I did not include antlr source or jar in it).
I included ParserProject.jar as well as a copy of antlr.jar in the
classpath of ParserPluginProject and compiled ParserPluginProject.

As you can imagine, ParserPluginProject calls ParserProject
The problem arises when I try to catch, within ParserPluginProject, an
exception (eg: antlr.TokenStreamException) thrown by ParserProject:
I'm not able to catch them!
As I mentioned, these exceptions are defined in antlr.jar.

I'll try to explain better happens with this code snippet:

try {
  ParserProject.parseFormula(formula);
} catch (antlr.RecognitionException e) {
  System.err.println("1 - RecognitionException: " + e.getClass());
} catch (antlr.TokenStreamRecognitionException e) {
  System.err.println("2 - TokenStreamRecognitionException: " +
e.getClass());
} catch (antlr.TokenStreamException e) {
  System.err.println("3 - TokenStreamException: " + e.getClass());
} catch (Exception e) {
  System.err.println("4 - Exception class: " + e.getClass());
  if (e instanceof antlr.TokenStreamException)
    System.err.println("ok");
  else
    System.err.println("different");
}


The above code snippet gives the following results:

run:
     [java] [error] 4 - Exception class: class
antlr.TokenStreamRecognitionException
     [java] [error] different

The code in the first three catch blocks are never reached!

Seems that they are two different definitions of the exception
TokenStreamRecognitionException, but I'm using two identical copies of
 antlr.jar for both projects!!
I really do not understand what is happening!

Regards,
  Xserty




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list