0

I am not able to instantiate Tidy as

Tidy t= new Tidy(); 

in my java code.

This jar is in my class path, and there are no compilation errors.

My code exits to the finally block after hitting this line without getting into the catch block, skipping any code after the line.

J Richard Snape
  • 20,116
  • 5
  • 51
  • 79
Thushar P Sujir
  • 201
  • 1
  • 2
  • 11
  • What error or exception do you get? Is there a stacktrace? – Thilo Mar 16 '15 at 10:09
  • 1
    If no exception is caught, it might be a Throwable: http://stackoverflow.com/questions/2129647/exception-vs-throwable-in-java – Eric Mar 16 '15 at 10:10
  • Like I mentioned, It jumps to the finally block...There is no exception – Thushar P Sujir Mar 16 '15 at 10:11
  • Can you show the code block in question? Then this question will be much easier to answer (e.g. what's in the `try` block after the line in question, what is `Tidy` - your own class, a class from a framework etc?) – J Richard Snape Mar 16 '15 at 10:30
  • Probably that means you're catching the wrong thing in your catch block. Catch Throwable (temporarily) to make sure. – Joeri Hendrickx Mar 16 '15 at 10:50

2 Answers2

0

Quote from "Ray Hidayat" from this StackOverflow question/answer.

Throwable is the superclass to Exception and Error, so you would catch Throwable if you wanted to not only catch Exceptions but Errors, that's the point in having it. The thing is, Errors are generally things which a normal application wouldn't and shouldn't catch, so just use Exception unless you have a specific reason to use Throwable.

I'm guessing an Error might be being thrown in your case. Try catching Throwable just to check, but as mentioned in the quote you shouldn't really catch Throwable.

Community
  • 1
  • 1
Eric
  • 1,321
  • 2
  • 15
  • 30
  • It was a Throwable. Turns out, there was a mismatch between my build time class path and run time class path, It worked after adding the jTidy jar to my runtime classpath. – Thushar P Sujir Mar 16 '15 at 10:52
-1

I suggest you to add a catch for Throwable before the finally block, and try again to see if your code throws another exception.

try {
    } catch (Throwable e) {
        e.printStackTrace();
    } finally { ... }
}
Markus W Mahlberg
  • 19,711
  • 6
  • 65
  • 89