Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

can't catch exception

  Asked By: Maria    Date: Dec 02    Category: Java    Views: 665
  

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!

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on can't catch exception Or get search suggestion and latest updates.




Tagged: